From 2ad96ed22c9773282145f191b2a8b0520949117c Mon Sep 17 00:00:00 2001 From: Scott Clayton Date: Sat, 17 Dec 2016 11:56:42 -0600 Subject: [PATCH] Fixed double captures --- Chase.Engine/Position.cs | 2 +- Chase.Tests/SearchTests.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Chase.Engine/Position.cs b/Chase.Engine/Position.cs index 836212e..e388b55 100644 --- a/Chase.Engine/Position.cs +++ b/Chase.Engine/Position.cs @@ -125,7 +125,7 @@ private void MakeMove(Move move, bool firstLevel, int basePieceCount) if ((sourcePiece > 0 && Board[move.ToIndex] < 0) || (sourcePiece < 0 && Board[move.ToIndex] > 0)) { // Keep track of how many points the enemy will need to distribute to other die - PointsToDistribute = Math.Abs(Board[move.ToIndex]); + PointsToDistribute += Math.Abs(Board[move.ToIndex]); } // Are we landing on the chamber? diff --git a/Chase.Tests/SearchTests.cs b/Chase.Tests/SearchTests.cs index 8c367b5..16b17ae 100644 --- a/Chase.Tests/SearchTests.cs +++ b/Chase.Tests/SearchTests.cs @@ -15,10 +15,18 @@ public class SearchTests public void TestGetBestMove() { Search search = new Search(); - SearchResult result = search.GetBestMove(Position.FromStringNotation("1bcdedcba/9/9/9/9/9/9/4a4/BBBDEDBBB b"), new SearchArgs(1, -1)); + SearchResult result; // The only sensible move is to capture on A5 + result = search.GetBestMove(Position.FromStringNotation("1bcdedcba/9/9/9/9/9/9/4a4/BBBDEDBBB b"), new SearchArgs(1, -1)); Assert.AreEqual(76, result.BestMove.ToIndex); + + // Splitting on the chamber captures two pieces, so we need to make sure pieces to distribute is 2 + Position position = Position.FromStringNotation("1bcdedcb1/9/9/9/5a3/4a4/5B3/9/A1CDEDCBA r"); + result = search.GetBestMove(position, new SearchArgs(1, -1)); + Assert.AreEqual("C6-CH", result.BestMove.ToString()); + position.MakeMove(result.BestMove); + Assert.AreEqual(2, position.PointsToDistribute); } } }