Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lk #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

lk #8

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .classpath
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="lib" path="C:/Users/Rand3/Downloads/othello/othello/sdks/java/AI/lib/gson-2.8.5.jar"/>
<classpathentry kind="lib" path="/Users/samventocilla/Downloads/othello/sdks/java/AI/lib/gson-2.8.5.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions bin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/com/
Binary file modified bin/com/atomicobject/othello/LegalMoves.class
Binary file not shown.
47 changes: 26 additions & 21 deletions src/com/atomicobject/othello/LegalMoves.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
public class LegalMoves {
int player;
int opponent;
//GameState gameState = new GameState();

// GameState gameState = new GameState();
public LegalMoves(GameState game) {
player = game.getPlayer();
opponent = getOpponent();
player = game.getPlayer();
opponent = getOpponent();
}

/**
Expand All @@ -31,9 +32,9 @@ else if (!isEmpty(move, moveR, moveC))
return false;

// check if it captures a piece
else if(!flipsPiece(move, moveR, moveC))
else if (!flipsPiece(move, moveR, moveC))
return false;

return true;
}

Expand All @@ -46,7 +47,7 @@ public boolean onBoard(int moveR, int moveC) {

// check if there is already a piece on that spot of the board
public boolean isEmpty(int[][] move, int moveR, int moveC) {
if (onBoard(moveR, moveC) ) {
if (onBoard(moveR, moveC)) {
if (move[moveR][moveC] != 0)
return false;
return true;
Expand All @@ -56,20 +57,24 @@ public boolean isEmpty(int[][] move, int moveR, int moveC) {

// check to make sure that the move flips an opponent's piece
public boolean flipsPiece(int[][] move, int moveR, int moveC) {
for (int r = -1; r < 2; r++)
for (int c = -1; c < 2; c++)
if (onBoard(moveR + r, moveC + c))
if (move[r + moveR][c + moveC] == opponent) {
int mult = 2;
while (onBoard(moveR + mult*r, moveC + mult*c)) {
if (move[moveR + mult * r][moveC + mult * c] == player) {
return true;
}
mult++;
}
}
return false;

// for (int r = -1; r < 2; r++)
// for (int c = -1; c < 2; c++) {
// int mult = 1;
// if (onBoard(moveR + r, moveC + c))
// if (move[moveR + r * mult][moveC + c * mult] == opponent)
// while (true) {
// mult++;
// if (onBoard(moveR + r * mult, moveC + c * mult)) {
// if (move[moveR + r * mult][moveC + c * mult] == player) {
// return true;
// }
// } else
// break;
//
// }
//
// }
// return false;
return true;
}

}