Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
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;

Expand Down Expand Up @@ -38,16 +40,20 @@ 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));
assertFalse("Unexpected children", uctNode.hasChildren());
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);
1000.50122, uctNode.calculateUctValue(1.0, 1), TOL);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down