0% found this document useful (0 votes)
64 views17 pages

Final Da PDF

The document describes an Othello game component developed for a game programming assignment. It includes sections on the name of the game component, how it fits into the game, the story and rules of Othello, a description of how the component was designed and developed using game theory principles, how the component is used in playing the game, technical details of its implementation in Java using an IDE, example source code, and a comparison to existing Othello game components.

Uploaded by

Penchal Doggala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
64 views17 pages

Final Da PDF

The document describes an Othello game component developed for a game programming assignment. It includes sections on the name of the game component, how it fits into the game, the story and rules of Othello, a description of how the component was designed and developed using game theory principles, how the component is used in playing the game, technical details of its implementation in Java using an IDE, example source code, and a comparison to existing Othello game components.

Uploaded by

Penchal Doggala
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Game Programming

Assignment 2
Game Component Development

17BCE0918

D.PENCHAL REDDY

SLOT:G2

Developing a Part of a game or a Component of a game

1. Name of the game part

2. Specify in which part of the game the designed part belongs to

3. Story of the game

4. Description of design and development of the game part

5. Use of this part on playing the game

6. Specify in which language, tool, Game Engine and etc. you developed the game
part

7. Copy and Paste the Source code.

8. Describe the Source code you written

9. Screen snap shot of the game part which you designed

10. Compare your design with the existing game part available and identify what
innovation you did on the designing and what improvement you did on the design
of that part
OTHELLO GAME PART
1.Name of the game part
APPENDIX-A,B

An initial set up of the game; white squares are where the dark player can
potentially place counters, (as they play first) while grey squares are where
counters cannot be placed until the game state changes (or because counters
already exist there)

2. Specify in which part of the game the designed part belongs to


A state following on from the initial state, where the dark player has placed a
counter, resulting in a light counter being flipped to dark. The white grid squares
show where the light player can place a counter

3. Story of the game


Othello (sometimes referred to by its old name of Reversi) is a table top board game
invented in the 19th century, where players place coloured counters onto an 8 by
8 board with the intention of flipping the other counters to their colours. This is
done by forming a line between a placed counter and another counter of that
colour on the board, which flips all other counters along said line to the colour of
the placed counter. This operation of creating the line between two counters of
the same colour is also known as bracketing. Play begins with two dark and two
light counters placed at the centre four squares of the game board, with each
counter being diagonally adjacent to the other counter of its colour. Players take
turns placing counters onto the board, with the player using the dark counters
going first. Counters may only be played onto the board in positions where an
existing placed counter is within a one square radius, and if placing the counter will
cause other counters to 5 be flipped. If there are no places on the board that a
player can place a counter on, then their turn is skipped, and the other player gets
to play a counter instead. The game ends when neither player can play a counter
on their turns, or when the board is full of counters, whichever comes first. A
selection of example Othello game states have been provided in Appendix A.

4. Description of design and development of the game part


Game theory is “the study of mathematical models of conflict and cooperation
between intelligent rational decision-makers” , and can be used by game-playing
AI to determine what move to play over others. Game theory is also used to
describe the way games operate, and thus helps to determine how they should be
evaluated. For example, Othello would be described as a sequential game, since
players do not perform actions simultaneously; the possible states and moves of a
sequential game can be easily modeled as a decision tree, due to the branching
nature of the game states. Furthermore, Othello is considered as a game with
perfect information, meaning that all information about the game is visible to all
players. In comparison, a game with imperfect information has some information
that is not always visible to a player. For example, in a game of poker, a player has
no way of knowing an opponent’s hand until the end of the round, so the
information they hold about the game, and by extension their estimation of their
chances of winning, is imperfect. Additionally, Othello is what’s known as a zero-
sum game, which describes a game where the value gained by one player is the
value lost for the other player. Knowledge of these kinds of properties and which
ones Othello fits is important when it comes to understanding the game itself, and
in creating an accurate simulation of the game programmatically.

5. Use of this part on playing the game


An AI that can play Othello should be able to make moves in the game based on
the data obtainable from 6 analysing the game state, such as the position of
counters, the remaining moves, the value of the board, etc.
Othello would be described as a sequential game, since players do not perform
actions simultaneously; the possible states and moves of a sequential game can be
easily modeled as a decision tree, due to the branching nature of the game states.

6. Specify in which language, tool, Game Engine and etc. you developed
the game part
The hardware and software of the computer we used for these evaluations is as
follows:

• Processor: Intel Core i7-4690K @ 3.5GHz

• Graphics Card: NVidia GeForce GTX 970

• RAM: 16GB of DDR3 1666MHz RAM

• OS: Windows 10

• Java version: v1.8.0_131

7. Copy and Paste the Source code


4.1 Pseudo Code

Agent.java
package othelo;

public interface Agent {

MoveCoord findMove(char[][] board, char piece);

public class MoveCoord


{
private int row;

private int col;


/**
* constructor for a Pair of coordinates
*/
public MoveCoord(int row, int col)
{
this.row = row;
this.col = col;
}

/** accessor methods */


public int getRow()
{
return this.row;
}

public int getCol()


{
return this.col;
}

/** mutation methods */


public void setRow(int row)
{
this.row = row;
}

public void setCol(int col)


{
this.col = col;
}

/** takes a pair of x,y coordinates, converts to standard board notation */


public static String encode(int row, int col)
{
return ("" + new Character((char) ('A' + col)) + (row + 1));
}
}
/**
* Class for presenting the move and the score together
*/
public class MoveScore implements Comparable<MoveScore>{
private MoveCoord move ;
private int score ;

public MoveScore(MoveCoord move, int score){


this.move = move;
this.score = score;
}

public int getScore(){


return score ;
}

public MoveCoord getMove(){


return move ;
}

@Override
public int compareTo(MoveScore o) {
if(o.score > this.score)
return 1;
else if (o.score < this.score)
return -1;
else
return 0;
}
}

}
Board.java
package othelo;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.IOException;
import javax.imageio.ImageIO;

public class Board extends javax.swing.JPanel implements MouseListener {

/******************************/
/* CONSTANT FOR DRAWING BOARD */
/******************************/
/** size of board */
private static final int board_size = Othello.board_size;

/** border offset */


private static final int boarder_offset = 30;

/** board offset */


private static final int board_offset = 20;

/** border and board offset */


private static final int border_board_offset = boarder_offset + board_offset;

/** size of a square. */


private static final int square_width = 45;

/** size of the board in pixels */


private static final int board_size_pixel = (board_offset + boarder_offset) * 2 + square_width * board_size;

/** radius of a piece */


private static final int piece_width = 35;

/** offset piece inside a square */


private static final int square_offset = (square_width - piece_width) >> 1;
/** width of the border */
private static final int border_width = 3;

/** width of the division between square */


private static final int divide_width = 1;

/** board color */


private static final Color board_color = new Color(130, 130,128, 255);

/** squares' divide color */


private static final Color divide_color = Color.white;

/** color for susggest black piece */


private static final Color suggest_black_color = new Color(0, 0, 0, 50);

/** color for susggest white piece */


private static final Color suggest_white_color = new Color(255, 255, 255, 80);

/** color for board's texts */


private static final Color board_text_color = Color.black;

/** font for board's texts */


private static final Font board_font = new Font("AXURE handwriting", Font.BOLD, 20);

/** board column texts */


private static final String[] col_text = {"A", "B", "C", "D", "E", "F", "G", "H"};

/** board row texts */


private static final String[] row_text = {"1", "2", "3", "4", "5", "6", "7", "8"};

/***********************************/
/* END CONSTANTS FOR DRAWING BOARD */
/***********************************/

/** image of black piece */


public static BufferedImage BlackPieceImg = null;

/** image of white piece */


public static BufferedImage WhitePieceImg = null;
public Board() {
// add mouse listener
addMouseListener(this);

// set panel size to board size


this.setPreferredSize(new Dimension(board_size_pixel, board_size_pixel));

init();
}

private void init() {


// load image for pieces
try {
BlackPieceImg = ImageIO.read(this.getClass().getResourceAsStream("/img/blackpiece.png"));
WhitePieceImg = ImageIO.read(this.getClass().getResourceAsStream("/img/whitepiece.png"));
} catch (IOException e) {
e.printStackTrace();
}
}

/**
* Draw the board
*/
@Override
public void paint(Graphics g) {
// draw the board with board color
g.setColor(board_color);
g.fillRect(0, 0, board_size_pixel, board_size_pixel);

// draw board's texts


g.setColor(board_text_color);
g.setFont(board_font);
Graphics2D g2d = (Graphics2D)g;
FontMetrics fm = g2d.getFontMetrics();

for (int i = 0; i < col_text.length; ++i)


{
g.drawString// draw A-H
(
col_text[i], border_board_offset + square_width * i + (square_width - fm.stringWidth(col_text[i]))/2,
(boarder_offset + fm.getHeight()/2) / 2
);

g.drawString// draw 1-8


(
row_text[i],(boarder_offset - fm.stringWidth(row_text[i])) / 2, border_board_offset + square_width * i
+(square_width + fm.getHeight()) / 2
);
}

// draw border
g.setColor(divide_color);
//left line
g.fillRect(boarder_offset, boarder_offset, border_width, board_size_pixel - boarder_offset * 2);
//top line
g.fillRect(boarder_offset, boarder_offset, board_size_pixel - boarder_offset * 2, border_width);
//bottom line
g.fillRect(boarder_offset, board_size_pixel - boarder_offset,board_size_pixel - boarder_offset * 2 + border_width,
border_width);
//right line
g.fillRect(board_size_pixel - boarder_offset, boarder_offset,border_width, board_size_pixel - boarder_offset * 2 +
border_width);

// draw the squares' dividers


// horizontal
for (int i = 0; i <= 8; ++i)
{
g.fillRect(i * square_width + border_board_offset, border_board_offset, divide_width,
square_width * board_size);
}
// vertical
for (int i = 0; i <= 8; ++i)
{
g.fillRect(border_board_offset, i * square_width + border_board_offset, square_width *
board_size, divide_width);
}

char[][] board = Othello.getInstance().getBoard();


// draw pieces
for (int r = 0; r < 8; ++r)
for (int c = 0; c < 8; ++c) {
if (Othello.getInstance().isNewPiece(r, c))
{
drawNewPiece(g,r,c);
}

if (Othello.getInstance().isEffectedPiece(r, c))
{
drawEffectedPiece(g, r, c);
}

if (board[r][c] == Othello.blck_piece)
{
//draw black piece
drawPiece(g, BlackPieceImg, r, c);

} else if (board[r][c] == Othello.whte_piece)


{
//draw white piece
drawPiece(g, WhitePieceImg, r, c);
}
else if (board[r][c] == Othello.suggest_black)
{
//draw suggest for black
g.setColor(suggest_black_color);
drawSuggestedPiece(g,r,c);
}
else if (board[r][c] == Othello.suggest_white)
{
//draw suggest for white
g.setColor(suggest_white_color);
drawSuggestedPiece(g,r,c);
}
else
continue;

}
}

private void drawNewPiece(Graphics g, int row, int col) {


g.setColor(new Color(255, 110, 147, 100));
g.fillRect
(
(col * square_width) + border_board_offset + divide_width, (row * square_width) + border_board_offset +
divide_width,square_width - divide_width, square_width - divide_width
);
}

private void drawEffectedPiece(Graphics g, int row, int col) {


g.setColor(new Color(255, 110, 147, 80));
g.fillRect
(
(col * square_width) + border_board_offset + divide_width, (row * square_width) + border_board_offset +
divide_width, square_width - divide_width, square_width - divide_width
);
}

private void drawSuggestedPiece(Graphics g, int row, int col) {


g.fillOval
(
(col * square_width) + square_offset + border_board_offset, (row * square_width)+ square_offset +
border_board_offset,piece_width, piece_width
);
}

private void drawPiece(Graphics g, BufferedImage img, int row, int col) {


g.drawImage
(
img, (col * square_width) + square_offset + border_board_offset, (row * square_width) + square_offset +
border_board_offset, null
);
}
@Override
public void mouseReleased(MouseEvent e) {
if (Othello.getInstance().getGameState() == Othello.play && !Othello.getInstance().getIsCompTurn())
{
int col = (e.getX() - border_board_offset) / square_width;
int row = (e.getY() - border_board_offset) / square_width;
if (row >= 0 && row <8 && col >=0 && col < 8)
Othello.getInstance().movePiece(row, col);
}
}

@Override
public void mouseClicked(MouseEvent arg0) {
// TODO Auto-generated method stub

@Override
public void mouseEntered(MouseEvent arg0) {
// TODO Auto-generated method stub

@Override
public void mouseExited(MouseEvent arg0) {
// TODO Auto-generated method stub

@Override
public void mousePressed(MouseEvent arg0) {
// TODO Auto-generated method stub

}
}

8. Describe the Source code you written


MINMAX ALGORITHM
By using minmax algorithm we developed the code.Minimaxing is a method used
when evaluating a game’s decision tree to ensure that the move chosen by the
player maximizes the chance of a favourable outcome for them. A simplified
example of this in a game of Othello would be that a minimax evaluation on the
game tree would favour a move that increases the player’s score by three over a
move that would only increase the score by one, due to the larger perceived gain.
However, the minimax algorithm also evaluates the opponent’s moves, which
assumes that the opponent will always pick the move that minimizes the player’s
gain from a move. As a result, the algorithm reflects the best outcome for the player
should they choose that branch of the game tree. 9 The value returned by a
minimax search may only be accurate up to a certain number of moves in the
future, as there is a limit on how far an AI can predict, based on the available time
and computational power. Additionally, the success of a minimax algorithm is
directly related to the quality of the evaluation function, which is what determines
how valuable a move or game state is. As previously mentioned, an Othello
evaluation function could be based only on the difference in the two player’s
scores, resulting in values like +3, +1, -2, etc. However, this fails to consider the
multitude of other factors of an Othello game state, such as the number of corner
or edge pieces the player has, the maneuverability of the player, and more. These
factors can increase or decrease the value of the game state, and should be
appropriately considered when producing an evaluation function. A competent
evaluation function can be the difference between a good AI and a great AI.

Pruning
To improve the performance of a minimax or other tree searching algorithm,
branches of the tree can be pruned if expanding them would not be beneficial to
the outcome of the algorithm. For example, at a level of the tree where Player B is
looking to minimize the value of Player A’s next state, and where the two available
branches of the tree lead to values of -4 and -2 for Player A, the -2 branch can be
pruned. This is because a sensible Player B would never select a move that doesn’t
minimise the gain for Player A, so the -2 branch does not need to be evaluated. This
type of pruning is called Alpha-Beta Pruning, and can drastically increase the
performance of a tree search algorithm that uses it. Many other pruning algorithms
exist, but Alpha-Beta is well suited to a minimax-type algorithm. Effective use of
pruning will allow an AI to evaluate more games states within the allotted
processing time, thus improving the quality of its decisions.

9. Screen snap shot of the game part which you designed


10. Compare your design with the existing game part available and
identify what innovation you did on the designing and what
improvement you did on the design of that part.
Compared to the Othello starting configuration, the "parallel" starting
configuration does not offer a wide range of interesting lines of play. Also, parallel
starting configuration may be a White win with perfect play. The Othello starting
configuration is almost certainly a draw with perfect play, and there are many draw
lines to choose from.
Summary of the problem with parallel opening configuration: either player could
force a Reversi game to become more boring if they wished, and White could
possibly force a winning position from the start, which is less fun for Black.
1.In Reversi as it was originally played, the game was over as soon as either player
could not make a move. In Othello, the player without a move simply passes, and
the other player makes as many moves as needed before the first player can make
a move again. The game is only over once neither player can make a move.
This “no passing” rule in Reversi makes the game radically different and basically
screws up normal Othello strategy.
2.Aesthetic differences: Othello is always is played on a green board with black and
white discs. Reversi does not have predetermined disc colors. You can find discs in
a lot of colours, mostly blue, red, or green. Reversi boards are in different colors
and styles. Before 1975, Reversi never had a green board.

----------------------THE END----------------------------

You might also like