From 0d2954c0475fae0872daf29519de560cbdc4c7db Mon Sep 17 00:00:00 2001 From: Sailesh Date: Tue, 4 Apr 2017 12:00:55 -0400 Subject: [PATCH] Fix bug in result --- src/CheckersGameState3.java | 3 ++- src/Test.java | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/CheckersGameState3.java b/src/CheckersGameState3.java index 4b89228..c46313b 100644 --- a/src/CheckersGameState3.java +++ b/src/CheckersGameState3.java @@ -226,8 +226,9 @@ private void calculate_jumps(String path, int[] b, int orig, int delta1, int del public CheckersGameState3 result(Move x){ int[] newState = this.board.clone(); - newState[x.destination()] = this.board[x.source()]; + int type = this.board[x.source()]; newState[x.source()] = 0; + newState[x.destination()] = type; if(x.destination() < 4 && this.player == 2){ newState[x.destination()] = 4; } diff --git a/src/Test.java b/src/Test.java index 1938235..7cc7957 100644 --- a/src/Test.java +++ b/src/Test.java @@ -14,7 +14,7 @@ public static void main(String[] args){ String[] b2 = {"-", "-", "-", "b", "-", "b", "-", "b", "b", "-", "w", "-", "b", "-", "b", "-", - "-", "b", "-", "B", "-", "b", "-", "b", + "-", "-", "-", "B", "-", "-", "-", "b", "-", "-", "w", "-", "w", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "w", "-", "w", "-", "w", "-", "w", "-", @@ -30,6 +30,16 @@ public static void main(String[] args){ "-", "w", "-", "-", "-", "w", "-", "w", "-", "-", "w", "-", "w", "-", "w", "-"}; + String[] b4 = {"-", "-", "-", "b", "-", "b", "-", "b", + "b", "-", "-", "-", "b", "-", "b", "-", + "-", "-", "-", "B", "-", "-", "-", "b", + "-", "-", "w", "-", "w", "-", "-", "-", + "-", "-", "-", "-", "-", "-", "-", "-", + "w", "-", "w", "-", "w", "-", "w", "-", + "-", "w", "-", "-", "-", "w", "-", "w", + "w", "-", "w", "-", "w", "-", "w", "-"}; + + CheckersGameState s1 = new CheckersGameState3(1, b); CheckersGameState s2 = new CheckersGameState3(2, b); @@ -37,6 +47,7 @@ public static void main(String[] args){ CheckersGameState s4 = new CheckersGameState3(2, b2); CheckersGameState s5 = new CheckersGameState3(1, b3); CheckersGameState s6 = new CheckersGameState3(2, b3); + CheckersGameState s7 = new CheckersGameState3(1, b4); printMoves(s1); printMoves(s2); printMoves(s3); @@ -45,6 +56,8 @@ public static void main(String[] args){ s5.result(s5.actions().get(0)).printState(); printMoves(s6); s6.result(s6.actions().get(0)).printState(); + printMoves(s7); + s7.result(s7.actions().get(0)).printState(); } static void printMoves(CheckersGameState s){