public static void SelectPiece_test_moves(BoardSelectTestCase c) { var cfg = BoardTests.FiveByFive(); var b = new Board(cfg, c.Layout); var moveEventArgsReceived = new List <PieceMovedEventArgs>(); b.SubscibeToMoves((o, e) => moveEventArgsReceived.Add(e)); var xsInSelected = GetCharCoorinates(c.Selected, 'X'); Assert.That(xsInSelected.Count, Is.EqualTo(1)); var selected = xsInSelected.First(); b.SelectPiece(selected); // Skip asserting for moves if arguments empty. In some cases there are so many pieces moved that the single // digit encoding of the test cases doesn't work and the movement tests are left out. if (!string.IsNullOrEmpty(c.ExpectedMovesFrom) && !string.IsNullOrEmpty(c.ExpectedMovesTo)) { var moves = GetNumberCoordinates(c.ExpectedMovesFrom, c.ExpectedMovesTo); Assert.That( moveEventArgsReceived .Select(x => new Tuple <Vector2Int, Vector2Int>(x.OldCoordinates, x.NewCoordinates)), Is.EquivalentTo(moves), "Received move events not matching expected"); } }
public void CreateFromBoardData() { logic = new TwoHumanLogic(BoardTests.CreateBoardData()); logic.MakeMove(Color.Red); Assert.AreEqual(Color.Red, logic.Board.GetColor(0, 0)); Assert.AreEqual(1, logic.ActivePlayer); Assert.AreEqual(2, logic.GetPlayerScore(0)); }
public static void SelectPiece_test_add_piece_types(BoardSelectTestCase c) { var cfg = BoardTests.FiveByFive(); var b = new Board(cfg, c.Layout); var addEventArgsReceived = new List <PieceAddedEventArgs>(); b.SubscribeToAdds((o, e) => addEventArgsReceived.Add(e)); var xsInSelected = GetCharCoorinates(c.Selected, 'X'); Assert.That(xsInSelected.Count, Is.EqualTo(1)); var selected = xsInSelected.First(); b.SelectPiece(selected); Assert.That( addEventArgsReceived.All(x => x.PieceType >= 0 && x.PieceType < cfg.NumColors), "Added piece types not within configured range"); }
public static void SelectPiece_test_removes(BoardSelectTestCase c) { var cfg = BoardTests.FiveByFive(); var b = new Board(cfg, c.Layout); var removeEventArgsReceived = new List <PieceRemovedEventArgs>(); b.SubscribeToRemoves((o, e) => removeEventArgsReceived.Add(e)); var xsInSelected = GetCharCoorinates(c.Selected, 'X'); Assert.That(xsInSelected.Count, Is.EqualTo(1)); var selected = xsInSelected.First(); var removed = GetCharCoorinates(c.ExpectedRemovals, 'X'); b.SelectPiece(selected); Assert.That( removeEventArgsReceived.Select(x => x.Coordinates), Is.EquivalentTo(removed), "Received remove events not matching expected"); }
private static int GenerateBoardAndReturnPieceAt(string layout, int x, int y) { var b = new Board(BoardTests.FiveByFive(), layout); return(b.At(x, y)); }