SlideShare a Scribd company logo
Need to make a Reversi/Othello Board game in JAVA
The board size can be N x N (so 4x4 is default, and it could be larger like 5x5, 6x6 etc. NEEDS
TO BE ABLE TO WORK WITH ODD SIZE)
Player 1 is going to be you and your going to be the black tiles, and the AI is going to be the
white tiles. Black tiles will start the game, and then white will go after them, then back to black,
repeat. The players must put a disc of their color on an empty square, adjacent to their
opponent's disc. Any of the oppponents tiles in between the tile put down, and another of your
tiles will cause them to flip to your color. The winner is decided when the board is completely
filled or no viable moves are left, and whoever has the most pieces.
This program is meant to be simple design (no GUI or big interface designs), broken into
multiple classes (can be extension's off the class or abstract interface off each other), and the
user will be entering the coordinates of where to put the pieces (so just using scanner method)?.
The start of the game must always have 4 tiles put down in the center (so the center can change
depending on the size of the board), and the gameplay would look something like this
Again, coding done in JAVA is what I'm looking for.
Scenario in which the game ends early.
JAVA code BW Success: Black move at C1, 0) BW Score: Black: 4, White: 1 Success: White
move at C2, 0D
Solution
package Reversi_Othello_GameReversiOthello;
import java.awt.*;
import java.applet.*;
public class Reversi_Othello_GameReversiOthello extends Applet implements Runnable {
Thread runner; // declare a thread for this GameReversiOthello
boolean black_shown = false; // flag to signal pause
boolean show_em = false;
final int BLACK = 1; // declare state of each square
final int WHITE = 2;
final int EMPTY = 0;
final int OFFBOARD = -1;
final static int GameReversiOthello[][] = new int[10][10]; //10x10 matrix of squares
protected int Count_Black = 0;
protected int Count_White = 0;
Event evt;
int x, y;
public void start() // create a thread and start it
{
if (runner == null) {
black_shown = false;
runner = new Thread(this);
runner.start();
}
}
public void stop() // stop the thread
{
if (runner != null) {
runner.stop();
runner = null;
black_shown = false;
}
}
public synchronized void run() // initialize screen
{
setBackground(Color.green);
for (int i = 0; i < 10; i++) // initialize off-board squares
{
GameReversiOthello[i][0] = OFFBOARD;
GameReversiOthello[i][9] = OFFBOARD;
GameReversiOthello[0][i] = OFFBOARD;
GameReversiOthello[9][i] = OFFBOARD;
}
for (int i = 1; i < 9; i++) // initialize GameReversiOthello board to be empty
{
for (int j = 1; j < 9; j++) {
GameReversiOthello[i][j] = EMPTY;
}
}
GameReversiOthello[4][4] = WHITE; // except for initial set up
GameReversiOthello[5][4] = BLACK;
GameReversiOthello[4][5] = BLACK;
GameReversiOthello[5][5] = WHITE;
while (runner != null) // signal thread to wait after painting
{ // black and before white responds
while (!black_shown) {
try {
wait();
} catch (InterruptedException e) {
}
black_shown = false;
showStatus("You Move is Awesome!! Keep Going");
pause(1000);
whiteResponds();
}
}
}
// BLACK clicked on a square - update screen
public synchronized boolean mouseUp(Event evt, int x, int y) {
Dimension d = size(); // find out which square was clicked
int c = (x * 8) / d.width + 1; // column
int r = (y * 8) / d.height + 1; // row
boolean black_done; // true if black cannot move anywhere
if (MoveLegal(r, c, BLACK, WHITE, true)) {
GameReversiOthello[r][c] = BLACK; // set that square to black
repaint();
black_shown = true;
notify();
} else {
showStatus("Not a legal move");
}
black_done = true; // check if black can move anywhere
for (int i = 1; i < 9; i++) {
for (int j = 1; j < 9; j++) {
if (MoveLegal(i, j, BLACK, WHITE, false)) {
black_done = false;
}
}
}
if (black_done) // black cannot move - white finishes up
{
for (int i = 1; i < 65; i++) {
whiteResponds();
}
}
return true;
}
// computer responds with a move
public void whiteResponds() {
boolean found; // true if a legal square is found
int i, j; // indices for loops
found = false;
if (MoveLegal(1, 1, WHITE, BLACK, true)) // first check corners
{
GameReversiOthello[1][1] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(8, 8, WHITE, BLACK, true))) {
GameReversiOthello[8][8] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(1, 8, WHITE, BLACK, true))) {
GameReversiOthello[1][8] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(8, 1, WHITE, BLACK, true))) {
GameReversiOthello[8][1] = WHITE;
found = true;
}
i = 3; // check center squares
while ((!found) && (i < 7)) {
j = 3;
while ((!found) && (j < 7)) {
if (MoveLegal(i, j, WHITE, BLACK, true)) {
GameReversiOthello[i][j] = WHITE;
found = true;
}
j++;
}
i++;
}
i = 3;
while ((!found) && (i < 7)) // then check edges except for those
{ // surrounding a corner
if (MoveLegal(1, i, WHITE, BLACK, true)) {
GameReversiOthello[1][i] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(8, i, WHITE, BLACK, true))) {
GameReversiOthello[8][i] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(i, 1, WHITE, BLACK, true))) {
GameReversiOthello[i][1] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(i, 8, WHITE, BLACK, true))) {
GameReversiOthello[i][8] = WHITE;
found = true;
}
i++;
}
i = 3;
while ((!found) && (i < 7)) // next check inner edges
{
if (MoveLegal(2, i, WHITE, BLACK, true)) {
GameReversiOthello[2][i] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(7, i, WHITE, BLACK, true))) {
GameReversiOthello[7][i] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(i, 2, WHITE, BLACK, true))) {
GameReversiOthello[i][2] = WHITE;
found = true;
}
if ((!found) && (MoveLegal(i, 7, WHITE, BLACK, true))) {
GameReversiOthello[i][7] = WHITE;
found = true;
}
i++;
}
i = 1; // finally squares surrounding a corner
while ((!found) && (i < 9)) {
j = 1;
while ((!found) && (j < 9)) {
if (MoveLegal(i, j, WHITE, BLACK, true)) {
found = true;
GameReversiOthello[i][j] = WHITE;
}
j++;
}
i++;
}
repaint();
}
// decide if the move is legal
public boolean MoveLegal(int r, int c, int color, int othercolor,
boolean flip) {
int i, j; // position on board
boolean legal; // true if legal move
int stepcount; // counts the stepping
// across the board
legal = false;
if (GameReversiOthello[r][c] == EMPTY) // square clicked must be empty
{
for (int xdir = -1; xdir < 2; xdir++) {
for (int ydir = -1; ydir < 2; ydir++) {
stepcount = 0;
do {
stepcount++;
i = r + stepcount * xdir; // so many steps along x-axis
j = c + stepcount * ydir; // so many steps along y-axis
} while ((i > 0) && (i < 9) && (j > 0) && (j < 9)
&& (GameReversiOthello[i][j] == othercolor));
if ((i > 0) && (i < 9) && (j > 0) && (j < 9)
&& (stepcount > 1)
&& // You must move more than one step for legal move
(GameReversiOthello[i][j] == color)) {
legal = true;
if (flip) {
for (int k = 1; k < stepcount; k++) {
GameReversiOthello[r + xdir * k][c + ydir * k] = color;
}
}
}
}
}
}
if (legal == true) {
return true;
} else {
return false;
}
}
void pause(int time) // time delay
{
try {
runner.sleep(time);
} catch (InterruptedException e) {
}
}
// paint the screen with the right configuartion
public void paint(Graphics g) {
Dimension d = size();
g.setColor(Color.black);
int xoff = d.width / 8;
int yoff = d.height / 8;
Count_Black = 0; // initialize counts to 0
Count_White = 0;
boolean done; // true if GameReversiOthello is over
for (int i = 1; i <= 8; i++) // draw the lines
{
g.drawLine(i * xoff, 0, i * xoff, d.height);
g.drawLine(0, i * yoff, d.width, i * yoff);
}
for (int i = 1; i < 9; i++) // scan board for black discs
{
for (int j = 1; j < 9; j++) {
if (GameReversiOthello[i][j] == BLACK) // draw BLACK discs
{
g.fillOval((j * yoff + 3) - yoff, (i * xoff + 3) - xoff, 33, 33);
Count_Black++;
}
}
}
g.setColor(Color.white);
for (int i = 1; i < 9; i++) // scan board for white discs
{
for (int j = 1; j < 9; j++) {
if (GameReversiOthello[i][j] == WHITE) // draw WHITE discs
{
g.fillOval((j * yoff + 3) - yoff, (i * xoff + 3) - xoff, 33, 33);
Count_White++;
}
}
}
g.setColor(Color.red);
done = true;
for (int i = 1; i < 9; i++) {
for (int j = 1; j < 9; j++) {
if ((MoveLegal(i, j, BLACK, WHITE, false))
|| (MoveLegal(i, j, WHITE, BLACK, false))) {
done = false;
}
}
}
if (done == true) {
if (Count_White > Count_Black) {
g.drawString("Game won By White with " + Count_White + " discs.", 10, 20);
} else if (Count_Black > Count_White) {
g.drawString("Game won By Black " + Count_Black + " discs.", 10, 20);
} else {
g.drawString("Tied GameReversiOthello", 10, 20);
}
} else {
if (Count_White > Count_Black) {
g.drawString("White is winning with " + Count_White + " discs", 10, 20);
} else if (Count_Black > Count_White) {
g.drawString("Black is winning with " + Count_Black + " discs", 10, 20);
} else {
g.drawString("Currently the game is Tie", 10, 20);
}
}
if (show_em == true) {
for (int i = 1; i < 9; i++) {
for (int j = 1; j < 9; j++) {
if (MoveLegal(i, j, BLACK, WHITE, false)) {
g.fillOval((j * yoff + 15) - yoff, (i * xoff + 15) - xoff, 5, 5);
}
}
}
}
}
public void Action() {
if (show_em == false) {
show_em = true;
repaint();
} else {
show_em = false;
repaint();
}
}
}

More Related Content

Similar to Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf

The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
fonecomp
 
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdfC++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
aromalcom
 
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
fms12345
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
asif1401
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
armcomputers
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
Mahmoud Samir Fayed
 
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 TilePUzzle class Anderson, Franceschi public class TilePu.docx TilePUzzle class Anderson, Franceschi public class TilePu.docx
TilePUzzle class Anderson, Franceschi public class TilePu.docx
Komlin1
 
AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMIN
Ankit Gupta
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
calderoncasto9163
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdf
rajkumarm401
 
efy-articles
efy-articlesefy-articles
efy-articles
Lokesh Kumar
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
PiersRCoThomsonw
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
rajkumarm401
 
Project 2
Project 2Project 2
Project 2
umtkrc
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
anwarsadath111
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
anithareadymade
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
NayanOza
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
Mahmoud Samir Fayed
 

Similar to Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf (18)

The following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdfThe following code, is a one player battleship game in JAVA. Im tryi.pdf
The following code, is a one player battleship game in JAVA. Im tryi.pdf
 
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdfC++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
C++ Programming (Please help me!! Thank you!!)Problem A Win SimU.pdf
 
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdfNO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
NO PAPER ANSWERS. ALL ANSWER SUBMISSIONS SHOULD BE ABLE TO RUN WIT.pdf
 
The main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdfThe main class of the tictoe game looks like.public class Main {.pdf
The main class of the tictoe game looks like.public class Main {.pdf
 
i have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdfi have a runable code below that works with just guessing where the .pdf
i have a runable code below that works with just guessing where the .pdf
 
The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212The Ring programming language version 1.10 book - Part 71 of 212
The Ring programming language version 1.10 book - Part 71 of 212
 
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 TilePUzzle class Anderson, Franceschi public class TilePu.docx TilePUzzle class Anderson, Franceschi public class TilePu.docx
TilePUzzle class Anderson, Franceschi public class TilePu.docx
 
AI CHALLENGE ADMIN
AI CHALLENGE ADMINAI CHALLENGE ADMIN
AI CHALLENGE ADMIN
 
This is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdfThis is the Java code i have for a Battleship project i am working o.pdf
This is the Java code i have for a Battleship project i am working o.pdf
 
This is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdfThis is for an homework assignment using Java code. Here is the home.pdf
This is for an homework assignment using Java code. Here is the home.pdf
 
efy-articles
efy-articlesefy-articles
efy-articles
 
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
#include -stdio-h- #include -stdlib-h- #include -stdbool-h- #include - (1).docx
 
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdfObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
ObjectiveCreate a graphical game of minesweeper IN JAVA. The boar.pdf
 
Project 2
Project 2Project 2
Project 2
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
Here is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdfHere is the code for youimport java.util.Scanner; import java.u.pdf
Here is the code for youimport java.util.Scanner; import java.u.pdf
 
19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf19012011102_Nayan Oza_Practical-7_AI.pdf
19012011102_Nayan Oza_Practical-7_AI.pdf
 
The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202The Ring programming language version 1.8 book - Part 66 of 202
The Ring programming language version 1.8 book - Part 66 of 202
 

More from flashfashioncasualwe

How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdfHow does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
flashfashioncasualwe
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
flashfashioncasualwe
 
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdfFocus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
flashfashioncasualwe
 
Decision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdfDecision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdf
flashfashioncasualwe
 
Explain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdfExplain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdf
flashfashioncasualwe
 
During a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdfDuring a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdf
flashfashioncasualwe
 
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdfExplain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
flashfashioncasualwe
 
Describe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdfDescribe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdf
flashfashioncasualwe
 
Explain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdfExplain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdf
flashfashioncasualwe
 
Develop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdfDevelop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdf
flashfashioncasualwe
 
Describe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdfDescribe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdf
flashfashioncasualwe
 
All answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdfAll answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdf
flashfashioncasualwe
 
C programming tweak needed for a specific program.This is the comp.pdf
C programming tweak needed for a specific program.This is the comp.pdfC programming tweak needed for a specific program.This is the comp.pdf
C programming tweak needed for a specific program.This is the comp.pdf
flashfashioncasualwe
 
Add to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdfAdd to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdf
flashfashioncasualwe
 
Write an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdfWrite an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdf
flashfashioncasualwe
 
which of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdfwhich of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdf
flashfashioncasualwe
 
2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf
flashfashioncasualwe
 
10. Benefits and costs of International Trade Search for a newspap.pdf
10. Benefits and costs of International Trade  Search for a newspap.pdf10. Benefits and costs of International Trade  Search for a newspap.pdf
10. Benefits and costs of International Trade Search for a newspap.pdf
flashfashioncasualwe
 
Why does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdfWhy does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdf
flashfashioncasualwe
 
Use the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdfUse the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdf
flashfashioncasualwe
 

More from flashfashioncasualwe (20)

How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdfHow does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
How does the mutation rate of speciation in the Dobzhansky- Muller m.pdf
 
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdfHello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
Hello. I need help fixing this Java Code on Eclipse. Please fix part.pdf
 
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdfFocus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
Focus on Writing 4. Supporting a Point of View Do you think Social Se.pdf
 
Decision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdfDecision-Making Across the Organization The board of trustees of a lo.pdf
Decision-Making Across the Organization The board of trustees of a lo.pdf
 
Explain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdfExplain the experience of African-Americans in the South over the co.pdf
Explain the experience of African-Americans in the South over the co.pdf
 
During a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdfDuring a diversity management session, a manager suggests that stereo.pdf
During a diversity management session, a manager suggests that stereo.pdf
 
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdfExplain why a mycoplasma PCR kit might give a negative result when u.pdf
Explain why a mycoplasma PCR kit might give a negative result when u.pdf
 
Describe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdfDescribe the difference between the MOV instruction and the LEA instr.pdf
Describe the difference between the MOV instruction and the LEA instr.pdf
 
Explain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdfExplain how enzymes work, explaining the four major types of metabol.pdf
Explain how enzymes work, explaining the four major types of metabol.pdf
 
Develop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdfDevelop an inventory management system for an electronics store. The .pdf
Develop an inventory management system for an electronics store. The .pdf
 
Describe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdfDescribe one event from your daily life when you have changed your o.pdf
Describe one event from your daily life when you have changed your o.pdf
 
All answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdfAll answers must be in your own wordsProvide a good, understandabl.pdf
All answers must be in your own wordsProvide a good, understandabl.pdf
 
C programming tweak needed for a specific program.This is the comp.pdf
C programming tweak needed for a specific program.This is the comp.pdfC programming tweak needed for a specific program.This is the comp.pdf
C programming tweak needed for a specific program.This is the comp.pdf
 
Add to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdfAdd to BST.java a method height() that computes the height of the tr.pdf
Add to BST.java a method height() that computes the height of the tr.pdf
 
Write an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdfWrite an awareness objective for a newly formed adolescent chemical .pdf
Write an awareness objective for a newly formed adolescent chemical .pdf
 
which of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdfwhich of these prokaryotes are most likely to be found in the immedi.pdf
which of these prokaryotes are most likely to be found in the immedi.pdf
 
2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf2. Why is only one end point observed for citric acid even though it .pdf
2. Why is only one end point observed for citric acid even though it .pdf
 
10. Benefits and costs of International Trade Search for a newspap.pdf
10. Benefits and costs of International Trade  Search for a newspap.pdf10. Benefits and costs of International Trade  Search for a newspap.pdf
10. Benefits and costs of International Trade Search for a newspap.pdf
 
Why does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdfWhy does the pattern in a shift register shift only one bit position.pdf
Why does the pattern in a shift register shift only one bit position.pdf
 
Use the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdfUse the Internet to identify three network firewalls, and create a t.pdf
Use the Internet to identify three network firewalls, and create a t.pdf
 

Recently uploaded

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
Dr. Mulla Adam Ali
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
Celine George
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
adhitya5119
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
GeorgeMilliken2
 

Recently uploaded (20)

Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 
Hindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdfHindi varnamala | hindi alphabet PPT.pdf
Hindi varnamala | hindi alphabet PPT.pdf
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17How to Make a Field Mandatory in Odoo 17
How to Make a Field Mandatory in Odoo 17
 
Advanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docxAdvanced Java[Extra Concepts, Not Difficult].docx
Advanced Java[Extra Concepts, Not Difficult].docx
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
What is Digital Literacy? A guest blog from Andy McLaughlin, University of Ab...
 

Need to make a ReversiOthello Board game in JAVAThe board size ca.pdf

  • 1. Need to make a Reversi/Othello Board game in JAVA The board size can be N x N (so 4x4 is default, and it could be larger like 5x5, 6x6 etc. NEEDS TO BE ABLE TO WORK WITH ODD SIZE) Player 1 is going to be you and your going to be the black tiles, and the AI is going to be the white tiles. Black tiles will start the game, and then white will go after them, then back to black, repeat. The players must put a disc of their color on an empty square, adjacent to their opponent's disc. Any of the oppponents tiles in between the tile put down, and another of your tiles will cause them to flip to your color. The winner is decided when the board is completely filled or no viable moves are left, and whoever has the most pieces. This program is meant to be simple design (no GUI or big interface designs), broken into multiple classes (can be extension's off the class or abstract interface off each other), and the user will be entering the coordinates of where to put the pieces (so just using scanner method)?. The start of the game must always have 4 tiles put down in the center (so the center can change depending on the size of the board), and the gameplay would look something like this Again, coding done in JAVA is what I'm looking for. Scenario in which the game ends early. JAVA code BW Success: Black move at C1, 0) BW Score: Black: 4, White: 1 Success: White move at C2, 0D Solution package Reversi_Othello_GameReversiOthello; import java.awt.*; import java.applet.*; public class Reversi_Othello_GameReversiOthello extends Applet implements Runnable { Thread runner; // declare a thread for this GameReversiOthello boolean black_shown = false; // flag to signal pause boolean show_em = false; final int BLACK = 1; // declare state of each square final int WHITE = 2; final int EMPTY = 0; final int OFFBOARD = -1; final static int GameReversiOthello[][] = new int[10][10]; //10x10 matrix of squares protected int Count_Black = 0; protected int Count_White = 0;
  • 2. Event evt; int x, y; public void start() // create a thread and start it { if (runner == null) { black_shown = false; runner = new Thread(this); runner.start(); } } public void stop() // stop the thread { if (runner != null) { runner.stop(); runner = null; black_shown = false; } } public synchronized void run() // initialize screen { setBackground(Color.green); for (int i = 0; i < 10; i++) // initialize off-board squares { GameReversiOthello[i][0] = OFFBOARD; GameReversiOthello[i][9] = OFFBOARD; GameReversiOthello[0][i] = OFFBOARD; GameReversiOthello[9][i] = OFFBOARD; } for (int i = 1; i < 9; i++) // initialize GameReversiOthello board to be empty { for (int j = 1; j < 9; j++) { GameReversiOthello[i][j] = EMPTY; } } GameReversiOthello[4][4] = WHITE; // except for initial set up GameReversiOthello[5][4] = BLACK;
  • 3. GameReversiOthello[4][5] = BLACK; GameReversiOthello[5][5] = WHITE; while (runner != null) // signal thread to wait after painting { // black and before white responds while (!black_shown) { try { wait(); } catch (InterruptedException e) { } black_shown = false; showStatus("You Move is Awesome!! Keep Going"); pause(1000); whiteResponds(); } } } // BLACK clicked on a square - update screen public synchronized boolean mouseUp(Event evt, int x, int y) { Dimension d = size(); // find out which square was clicked int c = (x * 8) / d.width + 1; // column int r = (y * 8) / d.height + 1; // row boolean black_done; // true if black cannot move anywhere if (MoveLegal(r, c, BLACK, WHITE, true)) { GameReversiOthello[r][c] = BLACK; // set that square to black repaint(); black_shown = true; notify(); } else { showStatus("Not a legal move"); } black_done = true; // check if black can move anywhere for (int i = 1; i < 9; i++) { for (int j = 1; j < 9; j++) { if (MoveLegal(i, j, BLACK, WHITE, false)) { black_done = false; }
  • 4. } } if (black_done) // black cannot move - white finishes up { for (int i = 1; i < 65; i++) { whiteResponds(); } } return true; } // computer responds with a move public void whiteResponds() { boolean found; // true if a legal square is found int i, j; // indices for loops found = false; if (MoveLegal(1, 1, WHITE, BLACK, true)) // first check corners { GameReversiOthello[1][1] = WHITE; found = true; } if ((!found) && (MoveLegal(8, 8, WHITE, BLACK, true))) { GameReversiOthello[8][8] = WHITE; found = true; } if ((!found) && (MoveLegal(1, 8, WHITE, BLACK, true))) { GameReversiOthello[1][8] = WHITE; found = true; } if ((!found) && (MoveLegal(8, 1, WHITE, BLACK, true))) { GameReversiOthello[8][1] = WHITE; found = true; } i = 3; // check center squares while ((!found) && (i < 7)) { j = 3; while ((!found) && (j < 7)) {
  • 5. if (MoveLegal(i, j, WHITE, BLACK, true)) { GameReversiOthello[i][j] = WHITE; found = true; } j++; } i++; } i = 3; while ((!found) && (i < 7)) // then check edges except for those { // surrounding a corner if (MoveLegal(1, i, WHITE, BLACK, true)) { GameReversiOthello[1][i] = WHITE; found = true; } if ((!found) && (MoveLegal(8, i, WHITE, BLACK, true))) { GameReversiOthello[8][i] = WHITE; found = true; } if ((!found) && (MoveLegal(i, 1, WHITE, BLACK, true))) { GameReversiOthello[i][1] = WHITE; found = true; } if ((!found) && (MoveLegal(i, 8, WHITE, BLACK, true))) { GameReversiOthello[i][8] = WHITE; found = true; } i++; } i = 3; while ((!found) && (i < 7)) // next check inner edges { if (MoveLegal(2, i, WHITE, BLACK, true)) { GameReversiOthello[2][i] = WHITE; found = true; }
  • 6. if ((!found) && (MoveLegal(7, i, WHITE, BLACK, true))) { GameReversiOthello[7][i] = WHITE; found = true; } if ((!found) && (MoveLegal(i, 2, WHITE, BLACK, true))) { GameReversiOthello[i][2] = WHITE; found = true; } if ((!found) && (MoveLegal(i, 7, WHITE, BLACK, true))) { GameReversiOthello[i][7] = WHITE; found = true; } i++; } i = 1; // finally squares surrounding a corner while ((!found) && (i < 9)) { j = 1; while ((!found) && (j < 9)) { if (MoveLegal(i, j, WHITE, BLACK, true)) { found = true; GameReversiOthello[i][j] = WHITE; } j++; } i++; } repaint(); } // decide if the move is legal public boolean MoveLegal(int r, int c, int color, int othercolor, boolean flip) { int i, j; // position on board boolean legal; // true if legal move int stepcount; // counts the stepping // across the board legal = false;
  • 7. if (GameReversiOthello[r][c] == EMPTY) // square clicked must be empty { for (int xdir = -1; xdir < 2; xdir++) { for (int ydir = -1; ydir < 2; ydir++) { stepcount = 0; do { stepcount++; i = r + stepcount * xdir; // so many steps along x-axis j = c + stepcount * ydir; // so many steps along y-axis } while ((i > 0) && (i < 9) && (j > 0) && (j < 9) && (GameReversiOthello[i][j] == othercolor)); if ((i > 0) && (i < 9) && (j > 0) && (j < 9) && (stepcount > 1) && // You must move more than one step for legal move (GameReversiOthello[i][j] == color)) { legal = true; if (flip) { for (int k = 1; k < stepcount; k++) { GameReversiOthello[r + xdir * k][c + ydir * k] = color; } } } } } } if (legal == true) { return true; } else { return false; } } void pause(int time) // time delay { try { runner.sleep(time); } catch (InterruptedException e) {
  • 8. } } // paint the screen with the right configuartion public void paint(Graphics g) { Dimension d = size(); g.setColor(Color.black); int xoff = d.width / 8; int yoff = d.height / 8; Count_Black = 0; // initialize counts to 0 Count_White = 0; boolean done; // true if GameReversiOthello is over for (int i = 1; i <= 8; i++) // draw the lines { g.drawLine(i * xoff, 0, i * xoff, d.height); g.drawLine(0, i * yoff, d.width, i * yoff); } for (int i = 1; i < 9; i++) // scan board for black discs { for (int j = 1; j < 9; j++) { if (GameReversiOthello[i][j] == BLACK) // draw BLACK discs { g.fillOval((j * yoff + 3) - yoff, (i * xoff + 3) - xoff, 33, 33); Count_Black++; } } } g.setColor(Color.white); for (int i = 1; i < 9; i++) // scan board for white discs { for (int j = 1; j < 9; j++) { if (GameReversiOthello[i][j] == WHITE) // draw WHITE discs { g.fillOval((j * yoff + 3) - yoff, (i * xoff + 3) - xoff, 33, 33); Count_White++; } }
  • 9. } g.setColor(Color.red); done = true; for (int i = 1; i < 9; i++) { for (int j = 1; j < 9; j++) { if ((MoveLegal(i, j, BLACK, WHITE, false)) || (MoveLegal(i, j, WHITE, BLACK, false))) { done = false; } } } if (done == true) { if (Count_White > Count_Black) { g.drawString("Game won By White with " + Count_White + " discs.", 10, 20); } else if (Count_Black > Count_White) { g.drawString("Game won By Black " + Count_Black + " discs.", 10, 20); } else { g.drawString("Tied GameReversiOthello", 10, 20); } } else { if (Count_White > Count_Black) { g.drawString("White is winning with " + Count_White + " discs", 10, 20); } else if (Count_Black > Count_White) { g.drawString("Black is winning with " + Count_Black + " discs", 10, 20); } else { g.drawString("Currently the game is Tie", 10, 20); } } if (show_em == true) { for (int i = 1; i < 9; i++) { for (int j = 1; j < 9; j++) { if (MoveLegal(i, j, BLACK, WHITE, false)) { g.fillOval((j * yoff + 15) - yoff, (i * xoff + 15) - xoff, 5, 5); } } }
  • 10. } } public void Action() { if (show_em == false) { show_em = true; repaint(); } else { show_em = false; repaint(); } } }