mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-23 07:29:02 -08:00
Debugging in Awari.java
This commit is contained in:
@@ -48,6 +48,7 @@ public class Awari{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void playerMove(boolean val){
|
private void playerMove(boolean val){
|
||||||
|
System.out.println("\nComputerSum PlayerSum"+sumComputer+" "+sumPlayer);
|
||||||
if(val == true)
|
if(val == true)
|
||||||
System.out.print("YOUR MOVE? ");
|
System.out.print("YOUR MOVE? ");
|
||||||
else
|
else
|
||||||
@@ -63,21 +64,32 @@ public class Awari{
|
|||||||
int last_pos = distribute(seeds,move);
|
int last_pos = distribute(seeds,move);
|
||||||
if(last_pos == playerHome){
|
if(last_pos == playerHome){
|
||||||
printBoard();
|
printBoard();
|
||||||
|
if(isGameOver(true)){
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
playerMove(false);
|
playerMove(false);
|
||||||
}
|
}
|
||||||
else if(board[last_pos] == 1&&last_pos != computerHome){
|
else if(board[last_pos] == 1&&last_pos != computerHome){
|
||||||
int opp = calculateOpposite(last_pos);
|
int opp = calculateOpposite(last_pos);
|
||||||
|
if(last_pos<6){
|
||||||
|
sumPlayer+=board[opp];
|
||||||
|
sumComputer-=board[opp];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
sumComputer+=board[opp];
|
||||||
|
sumPlayer-=board[opp];
|
||||||
|
}
|
||||||
board[last_pos]+=board[opp];
|
board[last_pos]+=board[opp];
|
||||||
board[opp] = 0;
|
board[opp] = 0;
|
||||||
printBoard();
|
printBoard();
|
||||||
if(isGameOver()){
|
if(isGameOver(false)){
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
computerMove(true);
|
computerMove(true);
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printBoard();
|
printBoard();
|
||||||
if(isGameOver()){
|
if(isGameOver(false)){
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
computerMove(true);
|
computerMove(true);
|
||||||
@@ -86,6 +98,7 @@ public class Awari{
|
|||||||
|
|
||||||
private void computerMove(boolean value){
|
private void computerMove(boolean value){
|
||||||
int val=-1;
|
int val=-1;
|
||||||
|
System.out.println("\nComputerSum PlayerSum"+sumComputer+" "+sumPlayer);
|
||||||
for(int i=0;i<6;i++){
|
for(int i=0;i<6;i++){
|
||||||
if(6-i == board[computerPits+i])
|
if(6-i == board[computerPits+i])
|
||||||
val = i;
|
val = i;
|
||||||
@@ -108,16 +121,24 @@ public class Awari{
|
|||||||
int last_pos = distribute(seeds,move+1);
|
int last_pos = distribute(seeds,move+1);
|
||||||
if(board[last_pos] == 1&&last_pos != playerHome){
|
if(board[last_pos] == 1&&last_pos != playerHome){
|
||||||
int opp = calculateOpposite(last_pos);
|
int opp = calculateOpposite(last_pos);
|
||||||
|
if(last_pos<6){
|
||||||
|
sumPlayer+=board[opp];
|
||||||
|
sumComputer-=board[opp];
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
sumComputer+=board[opp];
|
||||||
|
sumPlayer-=board[opp];
|
||||||
|
}
|
||||||
board[last_pos]+=board[opp];
|
board[last_pos]+=board[opp];
|
||||||
board[opp] = 0;
|
board[opp] = 0;
|
||||||
printBoard();
|
printBoard();
|
||||||
if(isGameOver()){
|
if(isGameOver(false)){
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
printBoard();
|
printBoard();
|
||||||
if(isGameOver()){
|
if(isGameOver(false)){
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -134,7 +155,7 @@ public class Awari{
|
|||||||
sumComputer-=seeds;
|
sumComputer-=seeds;
|
||||||
int last_pos = distribute(seeds,move+1);
|
int last_pos = distribute(seeds,move+1);
|
||||||
if(last_pos == computerHome){
|
if(last_pos == computerHome){
|
||||||
if(isGameOver() ){
|
if(isGameOver(true) ){
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
computerMove(false);
|
computerMove(false);
|
||||||
@@ -162,8 +183,10 @@ public class Awari{
|
|||||||
return 12-pos;
|
return 12-pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isGameOver(){
|
private boolean isGameOver(boolean show){
|
||||||
if(sumPlayer == 0 || sumComputer == 0){
|
if(sumPlayer == 0 || sumComputer == 0){
|
||||||
|
if(show)
|
||||||
|
printBoard();
|
||||||
System.out.println("GAME OVER");
|
System.out.println("GAME OVER");
|
||||||
if(board[playerHome]>board[computerHome]){
|
if(board[playerHome]>board[computerHome]){
|
||||||
System.out.println(String.format("YOU WIN BY %d POINTS",board[playerHome]-board[computerHome]));
|
System.out.println(String.format("YOU WIN BY %d POINTS",board[playerHome]-board[computerHome]));
|
||||||
|
|||||||
Reference in New Issue
Block a user