From 1f6e59718ae4039515b35405c394d7581a5f624e Mon Sep 17 00:00:00 2001 From: Rette66 Date: Thu, 2 Nov 2023 17:16:53 -0500 Subject: [PATCH 1/3] Fix testConstructionOfNodeWithNoChildren --- .../common/search/strategy/UctNodeTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java b/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java index e6f2b04..0a21e91 100644 --- a/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java +++ b/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java @@ -1,11 +1,14 @@ /* Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT */ package com.barrybecker4.game.twoplayer.common.search.strategy; +import java.io.*; import com.barrybecker4.common.format.FormatUtil; import com.barrybecker4.common.geometry.ByteLocation; import com.barrybecker4.game.common.MoveList; import com.barrybecker4.game.twoplayer.common.TwoPlayerMove; import com.barrybecker4.game.twoplayer.common.search.TwoPlayerMoveStub; +import com.barrybecker4.game.twoplayer.common.search.tree.NodeAttributes; + import junit.framework.TestCase; import org.junit.Test; @@ -38,6 +41,10 @@ public class UctNodeTest { public void testConstructionOfNodeWithNoChildren() { uctNode = new UctNode<>(P2_MOVE); + NodeAttributes tempAttr = new NodeAttributes(); + tempAttr.put("visits", "0"); + tempAttr.put("wins", "0.0"); + tempAttr.put("winRate", "0.50122"); assertEquals("Unexpected move", P2_MOVE, uctNode.move); assertEquals("Unexpected bestNode", null, uctNode.findBestChildMove(WIN_RATE)); @@ -45,9 +52,12 @@ public void testConstructionOfNodeWithNoChildren() { assertEquals("Unexpected numVisits", 0, uctNode.getNumVisits()); // The winrate is 0.5 (tie) + 10/WINNING = 0.50122 assertEquals("Unexpected winRate", 0.5012207f, uctNode.getWinRate(), TOL); - assertEquals("Unexpected attrs", "{wins=0.0, visits=0, winRate=0.50122}", uctNode.getAttributes().toString()); + assertEquals("Unexpected attrs", tempAttr, uctNode.getAttributes()); assertEquals("Unexpected uctValue", 1000.50122, uctNode.calculateUctValue(1.0, 1), TOL); + // System.out.println("\n\noutput result to check equal: \n"); + // System.out.println("Unexpected move " + P2_MOVE + uctNode.move); + } @Test From a178844d9be911349282585207a2e045815a4020 Mon Sep 17 00:00:00 2001 From: Rette66 Date: Thu, 2 Nov 2023 17:20:20 -0500 Subject: [PATCH 2/3] remove redundant space --- .../game/twoplayer/common/search/strategy/UctNodeTest.java | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java b/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java index 0a21e91..c29aba6 100644 --- a/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java +++ b/test/com/barrybecker4/game/twoplayer/common/search/strategy/UctNodeTest.java @@ -1,7 +1,6 @@ /* Copyright by Barry G. Becker, 2000-2011. Licensed under MIT License: http://www.opensource.org/licenses/MIT */ package com.barrybecker4.game.twoplayer.common.search.strategy; -import java.io.*; import com.barrybecker4.common.format.FormatUtil; import com.barrybecker4.common.geometry.ByteLocation; import com.barrybecker4.game.common.MoveList; @@ -54,10 +53,7 @@ public void testConstructionOfNodeWithNoChildren() { assertEquals("Unexpected winRate", 0.5012207f, uctNode.getWinRate(), TOL); assertEquals("Unexpected attrs", tempAttr, uctNode.getAttributes()); assertEquals("Unexpected uctValue", - 1000.50122, uctNode.calculateUctValue(1.0, 1), TOL); - // System.out.println("\n\noutput result to check equal: \n"); - // System.out.println("Unexpected move " + P2_MOVE + uctNode.move); - + 1000.50122, uctNode.calculateUctValue(1.0, 1), TOL); } @Test From f18fee476ae56ffc702b84badab923573d193ecb Mon Sep 17 00:00:00 2001 From: Rette66 Date: Thu, 2 Nov 2023 22:35:34 -0500 Subject: [PATCH 3/3] fix MoveMakerTest class --- .../twoplayer/mancala/move/MoveMakerTest.java | 80 ++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/test/com/barrybecker4/game/twoplayer/mancala/move/MoveMakerTest.java b/test/com/barrybecker4/game/twoplayer/mancala/move/MoveMakerTest.java index cbe189f..b9d20d4 100644 --- a/test/com/barrybecker4/game/twoplayer/mancala/move/MoveMakerTest.java +++ b/test/com/barrybecker4/game/twoplayer/mancala/move/MoveMakerTest.java @@ -93,10 +93,14 @@ public void testPlayer1CapturingMove() { MancalaMove move = new MancalaMove(true, new ByteLocation(1, 4), (byte)2, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(1,2), (byte)1); + tempCap.put(new ByteLocation(2,2), (byte)3); + // The captures describe where the captures stones came from assertEquals("Unexpected captures.", - "{(row=1, column=2)=1, (row=2, column=2)=3}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); // note that stones from 1, 2 and 2,2, are moved to p1's home verifier.checkOverallBoard(4, 0, 4, 0, 3, 3, 3, 0, @@ -109,9 +113,14 @@ public void testPlayer2CapturingMove() { MancalaMove move = new MancalaMove(false, new ByteLocation(2, 3), (byte)2, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(2,5), (byte)1); + tempCap.put(new ByteLocation(1,5), (byte)3); + + assertEquals("Unexpected captures.", - "{(row=1, column=5)=3, (row=2, column=5)=1}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); // note that stones from 1,2 and 2,2, are moved to p1's home verifier.checkOverallBoard(0, 3, 3, 3, 0, 3, 3, 4, @@ -129,10 +138,18 @@ public void testFinalPlayer1MoveOnPlayersSide() { MancalaMove move = new MancalaMove(true, new ByteLocation(1, 4), (byte)1, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(1,3), (byte)1); + tempCap.put(new ByteLocation(2,2), (byte)3); + tempCap.put(new ByteLocation(2,3), (byte)3); + tempCap.put(new ByteLocation(2,4), (byte)3); + tempCap.put(new ByteLocation(2,5), (byte)3); + tempCap.put(new ByteLocation(2,6), (byte)3); + tempCap.put(new ByteLocation(2,7), (byte)3); + assertEquals("Unexpected captures.", - "{(row=1, column=3)=1, (row=2, column=2)=3, (row=2, column=3)=3, (row=2, column=4)=3, " + - "(row=2, column=5)=3, (row=2, column=6)=3, (row=2, column=7)=3}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); verifier.checkOverallBoard(4, 0, 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, 0, 0); @@ -149,10 +166,18 @@ public void testFinalPlayer2MoveOnPlayersSide() { MancalaMove move = new MancalaMove(false, new ByteLocation(2, 4), (byte)1, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(2,5), (byte)1); + tempCap.put(new ByteLocation(1,2), (byte)3); + tempCap.put(new ByteLocation(1,3), (byte)3); + tempCap.put(new ByteLocation(1,4), (byte)3); + tempCap.put(new ByteLocation(1,5), (byte)3); + tempCap.put(new ByteLocation(1,6), (byte)3); + tempCap.put(new ByteLocation(1,7), (byte)3); + assertEquals("Unexpected captures.", - "{(row=1, column=2)=3, (row=1, column=3)=3, (row=1, column=4)=3, (row=1, column=5)=3, " + - "(row=1, column=6)=3, (row=1, column=7)=3, (row=2, column=5)=1}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); verifier.checkOverallBoard(15, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0); @@ -167,10 +192,17 @@ public void testFinalPlayer1MoveInHomeBin() { MancalaMove move = new MancalaMove(true, new ByteLocation(1, 2), (byte)1, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(2,2), (byte)3); + tempCap.put(new ByteLocation(2,3), (byte)3); + tempCap.put(new ByteLocation(2,4), (byte)3); + tempCap.put(new ByteLocation(2,5), (byte)3); + tempCap.put(new ByteLocation(2,6), (byte)3); + tempCap.put(new ByteLocation(2,7), (byte)3); + assertEquals("Unexpected captures.", - "{(row=2, column=2)=3, (row=2, column=3)=3, (row=2, column=4)=3, (row=2, column=5)=3, " + - "(row=2, column=6)=3, (row=2, column=7)=3}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); verifier.checkOverallBoard(1, 0, 0, 0, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0); @@ -185,10 +217,17 @@ public void testFinalPlayer2MoveInHomeBin() { MancalaMove move = new MancalaMove(false, new ByteLocation(2, 7), (byte)1, 0); moveMaker.makeMove(move); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(1,2), (byte)3); + tempCap.put(new ByteLocation(1,3), (byte)3); + tempCap.put(new ByteLocation(1,4), (byte)3); + tempCap.put(new ByteLocation(1,5), (byte)3); + tempCap.put(new ByteLocation(1,6), (byte)3); + tempCap.put(new ByteLocation(1,7), (byte)3); + assertEquals("Unexpected captures.", - "{(row=1, column=2)=3, (row=1, column=3)=3, (row=1, column=4)=3, (row=1, column=5)=3, " + - "(row=1, column=6)=3, (row=1, column=7)=3}", - move.getCaptures().toString()); + tempCap, + move.getCaptures()); verifier.checkOverallBoard(18, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0); } @@ -286,11 +325,16 @@ public void testCrazyP1Combo() { move5.setFollowUpMove(move6); moveMaker.makeMove(move1); + Captures tempCap = new Captures(); + tempCap.put(new ByteLocation(1,3), (byte)1); + tempCap.put(new ByteLocation(2,3), (byte)3); + + assertEquals("Unexpected captures.", "{}", move1.getCaptures().toString()); assertEquals("Unexpected captures.", - "{(row=1, column=3)=1, (row=2, column=3)=3}", - move6.getCaptures().toString()); + tempCap, + move6.getCaptures()); verifier.checkOverallBoard(9, 4, 0, 0, 0, 5, 6, 0, 3, 0, 3, 3, 3, 3);