Skip to content

Commit

Permalink
Added capture and point distribution logic
Browse files Browse the repository at this point in the history
  • Loading branch information
skotz committed Dec 14, 2016
1 parent f3432c3 commit fa53385
Show file tree
Hide file tree
Showing 4 changed files with 287 additions and 123 deletions.
6 changes: 6 additions & 0 deletions Chase.Engine/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ namespace Chase.Engine
{
public class Constants
{
public const int EvalPieceWeight = 100;

public const int EvalMobilityWeight = 1;

public const int MaximumPieceCount = 10;

public const int MinimumPieceCount = 5;
Expand All @@ -22,6 +26,8 @@ public class Constants

public const int InvalidMove = -1;

public const int InvalidTile = -2;

public static Random Rand = new Random();

public static Direction[] Directions = new Direction[]
Expand Down
28 changes: 27 additions & 1 deletion Chase.Engine/Move.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ public class Move
/// </summary>
public Direction FinalDirection { get; set; }

private static Dictionary<string, int> IndexLookup;

public static int GetIndexFromTile(string tile)
{
if (IndexLookup == null)
{
IndexLookup = new Dictionary<string, int>();
for (int i=0; i < Constants.BoardSize; i++)
{
IndexLookup.Add(GetTileFromIndex(i), i);
}
}

return IndexLookup.ContainsKey(tile) ? IndexLookup[tile] : Constants.InvalidTile;
}

public static string GetTileFromIndex(int index)
{
// Indexes of each piece on the board...
Expand Down Expand Up @@ -95,10 +111,20 @@ public override string ToString()
{
if (Increment > 0)
{
return GetTileFromIndex(ToIndex) + "+=" + Increment;
if (FromIndex >= 0)
{
// Distributing points to an adjacent piece
return GetTileFromIndex(FromIndex) + "-" + GetTileFromIndex(ToIndex) + "+=" + Increment;
}
else
{
// Distributing points after a capture
return GetTileFromIndex(ToIndex) + "+=" + Increment;
}
}
else
{
// Regular move
return GetTileFromIndex(FromIndex) + "-" + GetTileFromIndex(ToIndex);
}
}
Expand Down
Loading

0 comments on commit fa53385

Please sign in to comment.