Skip to content

Commit

Permalink
Added turn selector strategies
Browse files Browse the repository at this point in the history
  • Loading branch information
dodikk committed Dec 19, 2015
1 parent c05e5f3 commit 505871b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Reversi/Assets/ReversiKit/GreedyTurnSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Linq;
using System.Collections.Generic;

namespace ReversiKit
{
public class GreedyTurnSelector : ITurnSelector
{
public IReversiTurn SelectBestTurnOnBoard(
IEnumerable<IReversiTurn> validTurns,
IBoardState board)
{
IReversiTurn result =
validTurns.OrderByDescending(t => t.PositionsOfFlippedItems.Count())
.First();

return result;
}
}
}

22 changes: 22 additions & 0 deletions Reversi/Assets/ReversiKit/RandomTurnSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Linq;
using System.Collections.Generic;


namespace ReversiKit
{
public class RandomTurnSelector : ITurnSelector
{
public IReversiTurn SelectBestTurnOnBoard(
IEnumerable<IReversiTurn> validTurns,
IBoardState board)
{
Random rand = new Random();
int index = rand.Next(0, validTurns.Count());

IReversiTurn result = validTurns.ElementAt(index);
return result;
}
}
}

6 changes: 6 additions & 0 deletions Reversi/ReversiKit/ReversiKit/ReversiKit/ReversiKit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@
<Compile Include="..\..\..\Assets\ReversiKit\TurnCalculator.cs">
<Link>Impl\TurnCalculator.cs</Link>
</Compile>
<Compile Include="..\..\..\Assets\ReversiKit\GreedyTurnSelector.cs">
<Link>Impl\GreedyTurnSelector.cs</Link>
</Compile>
<Compile Include="..\..\..\Assets\ReversiKit\RandomTurnSelector.cs">
<Link>Impl\RandomTurnSelector.cs</Link>
</Compile>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
Expand Down

0 comments on commit 505871b

Please sign in to comment.