public void MakeMoveRaisesEvent() { // Given Piece rook = new Rook(Colour.White); StartSquare a1 = new StartSquare("a1"); DestinationSquare a4 = new DestinationSquare("a4"); long gameId = 101; Game target = new Game(gameId); target.Board.PutPieceOn(a1, rook); // When MakeMove command = new MakeMove(gameId, new Move(rook.Code, a1, a4)); target.MakeMove(command); // Then DomainEvent result = target.Events.Single(); Assert.IsInstanceOfType(result, typeof(MoveMade)); MoveMade movemade = (MoveMade)result; Assert.AreEqual(gameId, movemade.GameId); Assert.AreEqual('R', movemade.PieceCode); Assert.AreEqual("a1", movemade.StartSquare); Assert.AreEqual("a4", movemade.DestinationSquare); }
public void PieceMoustActuallyMove() { // Given Piece rook = new Rook(Colour.White); StartSquare a1 = new StartSquare("a1"); DestinationSquare a1AsWell = new DestinationSquare("a1"); long gameId = 101; Game target = new Game(gameId); target.Board.PutPieceOn(a1, rook); // When MakeMove command = new MakeMove(gameId, new Move(rook.Code, a1, a1AsWell)); Action act = () => { target.MakeMove(command); }; // Then var ex = Assert.ThrowsException <BusinessRuleViolationException>(act); Assert.AreEqual("Rule Violations: 1 violations have been detected.", ex.Message); Assert.AreEqual(1, ex.Violations.Count()); Assert.IsTrue(ex.Violations.Any(v => v.ViolationMessage == "The start square cannot be the same as the destination square.")); }
public static MakeMove FromDTO(long id, DTO.MakeMove dtoCommand) { string notation = dtoCommand.Notation; PieceCode pieceCode; StartSquare start; DestinationSquare destination; if ("RNBQK".Contains(notation.First())) { Enum.TryParse(dtoCommand.Notation.Substring(0, 1), out pieceCode); start = new StartSquare(dtoCommand.Notation.Substring(1, 2)); destination = new DestinationSquare(dtoCommand.Notation.Substring(4, 2)); } else { pieceCode = PieceCode.None; start = new StartSquare(dtoCommand.Notation.Substring(0, 2)); destination = new DestinationSquare(dtoCommand.Notation.Substring(3, 2)); } var move = new Move(pieceCode, start, destination); var result = new MakeMove(id, move); return(result); }
private void SquareView_Click(object sender, RoutedEventArgs e) { SquareView clickedSquare = sender as SquareView; if (StartSquare == null) { // Only highlight if it has a piece Square square = clickedSquare.DataContext as Square; if (square.HasPiece()) { StartSquare = clickedSquare; StartSquare.SetHighlightColor(); ShowMovePreviews(); } } else if ((StartSquare == clickedSquare) || (StartSquare != null && EndSquare != null)) { ClearSquares(); } else { EndSquare = clickedSquare; GameController.Update(); } }
// Start is called before the first frame update void Start() { sM = marker.GetComponent <LSLMarkerStream>(); m = Manager.GetComponent <Manager>(); insideSquareScript = startSquare.GetComponent <StartSquare>(); selectionSquareArousal.SetActive(false); selectionSquareValence.SetActive(false); selectionSquareDominance.SetActive(false); //Setting all SAM's off Arousal.SetActive(false); Valence.SetActive(false); Dominance.SetActive(false); //Get all SAM's Arousal A0 = Arousal.transform.GetChild(0).gameObject; A1 = Arousal.transform.GetChild(1).gameObject; A2 = Arousal.transform.GetChild(2).gameObject; A3 = Arousal.transform.GetChild(3).gameObject; A4 = Arousal.transform.GetChild(4).gameObject; //Get all SAM's Valence V0 = Valence.transform.GetChild(0).gameObject; V1 = Valence.transform.GetChild(1).gameObject; V2 = Valence.transform.GetChild(2).gameObject; V3 = Valence.transform.GetChild(3).gameObject; V4 = Valence.transform.GetChild(4).gameObject; //Get all SAM's Dominance D0 = Dominance.transform.GetChild(0).gameObject; D1 = Dominance.transform.GetChild(1).gameObject; D2 = Dominance.transform.GetChild(2).gameObject; D3 = Dominance.transform.GetChild(3).gameObject; D4 = Dominance.transform.GetChild(4).gameObject; }
public void IsVerticalMove() { StartSquare b2 = new StartSquare("b2"); DestinationSquare b7 = new DestinationSquare("b7"); Move move = new Move(PieceCode.R, b2, b7); bool result = move.IsVerticalMove(); Assert.AreEqual(true, result); }
public void IsNOVerticalMove() { StartSquare b2 = new StartSquare("b2"); DestinationSquare d3 = new DestinationSquare("d3"); Move move = new Move(PieceCode.R, b2, d3); bool result = move.IsVerticalMove(); Assert.AreEqual(false, result); }
public void IsHorizontalMove() { StartSquare b2 = new StartSquare("b2"); DestinationSquare d2 = new DestinationSquare("d2"); Move move = new Move(PieceCode.R, b2, d2); bool result = move.IsHorizontalMove(); Assert.AreEqual(true, result); }
public void AMoveHasAPieceStartAndDestination() { StartSquare e1 = new StartSquare("e1"); DestinationSquare d2 = new DestinationSquare("d2"); Move move = new Move(PieceCode.K, e1, d2); Assert.AreEqual(PieceCode.K, move.PieceCode); Assert.AreEqual(e1, move.StartSquare); Assert.AreEqual(d2, move.DestinationSquare); }
public void PieceMustAcuallyMove() { Piece rook = new Rook(Colour.Black); StartSquare d5 = new StartSquare("d5"); DestinationSquare d8 = new DestinationSquare("d8"); Move move = new Move(rook.Code, d5, d8); BusinessRule target = new PieceMustActuallyMove(move); IEnumerable <BusinessRuleViolation> violations = target.CheckRule(); Assert.IsNotNull(violations); Assert.IsFalse(violations.Any()); }
public void PieceMustAcuallyMove_ButDoesNot() { Piece rook = new Rook(Colour.Black); StartSquare d5 = new StartSquare("d5"); DestinationSquare d5AsWell = new DestinationSquare("d5"); Move move = new Move(rook.Code, d5, d5AsWell); BusinessRule target = new PieceMustActuallyMove(move); IEnumerable <BusinessRuleViolation> violations = target.CheckRule(); Assert.AreEqual(1, violations.Count()); Assert.IsTrue(violations.Any(v => v.ViolationMessage == "The start square cannot be the same as the destination square.")); }
public void IsNoKnightMove() { StartSquare d4 = new StartSquare("d4"); Move moved5 = new Move(PieceCode.N, d4, new DestinationSquare("d5")); Move moved1 = new Move(PieceCode.N, d4, new DestinationSquare("d1")); Move movef6 = new Move(PieceCode.N, d4, new DestinationSquare("f6")); Move movea1 = new Move(PieceCode.N, d4, new DestinationSquare("a1")); Move moveg4 = new Move(PieceCode.N, d4, new DestinationSquare("g4")); Assert.AreEqual(false, moved5.IsKnightMove(), "d4-d5 is not a knight move"); Assert.AreEqual(false, moved1.IsKnightMove(), "d4-d1 is not a knight move"); Assert.AreEqual(false, movef6.IsKnightMove(), "d4-f6 is not a knight move"); Assert.AreEqual(false, movea1.IsKnightMove(), "d4-a1 is not a knight move"); Assert.AreEqual(false, moveg4.IsKnightMove(), "d4-g4 is not a knight move"); }
public void IsNotOneStepInAnyDirection() { StartSquare b2 = new StartSquare("b2"); Move movea5 = new Move(PieceCode.K, b2, new DestinationSquare("a5")); Move moveb4 = new Move(PieceCode.K, b2, new DestinationSquare("b4")); Move moved4 = new Move(PieceCode.K, b2, new DestinationSquare("d4")); Move movee2 = new Move(PieceCode.K, b2, new DestinationSquare("e2")); Move moveh8 = new Move(PieceCode.K, b2, new DestinationSquare("h8")); Assert.AreEqual(false, movea5.IsOneStepInAnyDirection(), "a5 is not one step"); Assert.AreEqual(false, moveb4.IsOneStepInAnyDirection(), "b4 is not one step"); Assert.AreEqual(false, moved4.IsOneStepInAnyDirection(), "d4 is not one step"); Assert.AreEqual(false, movee2.IsOneStepInAnyDirection(), "e2 is not one step"); Assert.AreEqual(false, moveh8.IsOneStepInAnyDirection(), "h8 is not one step"); }
public void IsDiagonalMove() { StartSquare d5 = new StartSquare("d5"); Move movea2 = new Move(PieceCode.B, d5, new DestinationSquare("a2")); Move movea8 = new Move(PieceCode.B, d5, new DestinationSquare("a8")); Move moveg8 = new Move(PieceCode.B, d5, new DestinationSquare("g8")); Move moveh1 = new Move(PieceCode.B, d5, new DestinationSquare("h1")); Move movef3 = new Move(PieceCode.B, d5, new DestinationSquare("f3")); Move movef7 = new Move(PieceCode.B, d5, new DestinationSquare("f7")); Assert.AreEqual(true, movea2.IsDiagonalMove(), "d5-a2 is a diagonal move"); Assert.AreEqual(true, movea8.IsDiagonalMove(), "d5-a8 is a diagonal move"); Assert.AreEqual(true, moveg8.IsDiagonalMove(), "d5-g8 is a diagonal move"); Assert.AreEqual(true, moveh1.IsDiagonalMove(), "d5-h1 is a diagonal move"); Assert.AreEqual(true, movef3.IsDiagonalMove(), "d5-f3 is a diagonal move"); Assert.AreEqual(true, movef7.IsDiagonalMove(), "d5-f7 is a diagonal move"); }
public void IsNoDiagonalMove() { StartSquare d5 = new StartSquare("d5"); Move moved4 = new Move(PieceCode.B, d5, new DestinationSquare("d4")); Move moved6 = new Move(PieceCode.B, d5, new DestinationSquare("d6")); Move movea5 = new Move(PieceCode.B, d5, new DestinationSquare("a5")); Move moveh5 = new Move(PieceCode.B, d5, new DestinationSquare("h5")); Move movee7 = new Move(PieceCode.B, d5, new DestinationSquare("e7")); Move movef6 = new Move(PieceCode.B, d5, new DestinationSquare("f6")); Assert.AreEqual(false, moved4.IsDiagonalMove(), "d5-d4 is not a diagonal move"); Assert.AreEqual(false, moved6.IsDiagonalMove(), "d5-d6 is not a diagonal move"); Assert.AreEqual(false, movea5.IsDiagonalMove(), "d5-a5 is not a diagonal move"); Assert.AreEqual(false, moveh5.IsDiagonalMove(), "d5-h5 is not a diagonal move"); Assert.AreEqual(false, movee7.IsDiagonalMove(), "d5-e7 is not a diagonal move"); Assert.AreEqual(false, movef6.IsDiagonalMove(), "d5-f6 is not a diagonal move"); }
public void MakeMoveMovesPieceOnBoard() { // Given Piece rook = new Rook(Colour.White); StartSquare a1 = new StartSquare("a1"); DestinationSquare a4 = new DestinationSquare("a4"); Game target = new Game(1); target.Board.PutPieceOn(a1, rook); // When MakeMove command = new MakeMove(1, new Move(rook.Code, a1, a4)); target.MakeMove(command); // Then Assert.IsTrue(target.Board.IsEmptyAt(a1), "rook should not be on a1"); Assert.IsTrue(target.Board.HasThisPieceOn(a4, rook.Code), "rook should be on a4"); }
public void IsOneStepInAnyDirection() { StartSquare b2 = new StartSquare("b2"); Move movea3 = new Move(PieceCode.K, b2, new DestinationSquare("a3")); Move moveb3 = new Move(PieceCode.K, b2, new DestinationSquare("b3")); Move movec3 = new Move(PieceCode.K, b2, new DestinationSquare("c3")); Move movea2 = new Move(PieceCode.K, b2, new DestinationSquare("a2")); Move movec2 = new Move(PieceCode.K, b2, new DestinationSquare("c2")); Move movea1 = new Move(PieceCode.K, b2, new DestinationSquare("a1")); Move moveb1 = new Move(PieceCode.K, b2, new DestinationSquare("b1")); Move movec1 = new Move(PieceCode.K, b2, new DestinationSquare("c1")); Assert.AreEqual(true, movea3.IsOneStepInAnyDirection(), "a3 is one step"); Assert.AreEqual(true, moveb3.IsOneStepInAnyDirection(), "b3 is one step"); Assert.AreEqual(true, movec3.IsOneStepInAnyDirection(), "c3 is one step"); Assert.AreEqual(true, movea2.IsOneStepInAnyDirection(), "a2 is one step"); Assert.AreEqual(true, movec2.IsOneStepInAnyDirection(), "c2 is one step"); Assert.AreEqual(true, movea1.IsOneStepInAnyDirection(), "a1 is one step"); Assert.AreEqual(true, moveb1.IsOneStepInAnyDirection(), "b1 is one step"); Assert.AreEqual(true, movec1.IsOneStepInAnyDirection(), "c1 is one step"); }
public void IsKnightMove() { StartSquare d4 = new StartSquare("d4"); Move movee6 = new Move(PieceCode.N, d4, new DestinationSquare("e6")); Move movef5 = new Move(PieceCode.N, d4, new DestinationSquare("f5")); Move movef3 = new Move(PieceCode.N, d4, new DestinationSquare("f3")); Move movee2 = new Move(PieceCode.N, d4, new DestinationSquare("e2")); Move movec2 = new Move(PieceCode.N, d4, new DestinationSquare("c2")); Move moveb3 = new Move(PieceCode.N, d4, new DestinationSquare("b3")); Move moveb5 = new Move(PieceCode.N, d4, new DestinationSquare("b5")); Move movec6 = new Move(PieceCode.N, d4, new DestinationSquare("c6")); Assert.AreEqual(true, movee6.IsKnightMove(), "d4-e6 is a knight move"); Assert.AreEqual(true, movef5.IsKnightMove(), "d4-f5 is a knight move"); Assert.AreEqual(true, movef3.IsKnightMove(), "d4-f3 is a knight move"); Assert.AreEqual(true, movee2.IsKnightMove(), "d4-e2 is a knight move"); Assert.AreEqual(true, movec2.IsKnightMove(), "d4-c2 is a knight move"); Assert.AreEqual(true, moveb3.IsKnightMove(), "d4-b3 is a knight move"); Assert.AreEqual(true, moveb5.IsKnightMove(), "d4-b5 is a knight move"); Assert.AreEqual(true, movec6.IsKnightMove(), "d4-c6 is a knight move"); }
public MapSection[][] GenerateMap() { //fill a basic level with different squares const int mapHeight = 10; const int mapLength = mapHeight; var map = new MapSection[mapHeight][]; var squareNumber = 1; //The start square and end square will be added right under the for's var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { if (bonusCounter == 7 && counter != 5) { var rnd = new Random(); if (rnd.Next(0, 10) % 2 == 0) { map[i][j] = new MysterySquare(i, j); bonusCounter++; } else { map[i][j] = new BonusSquare(i, j); bonusCounter++; } map[i][j].Number = squareNumber; squareNumber++; bonusCounter = 0; counter++; } else if (counter == 5) { var rnd = new Random(); if (rnd.Next(0, 4) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter++; } else { map[i][j] = new GoBackSquare(i, j); counter++; } counter = 0; map[i][j].Number = squareNumber; squareNumber++; } else { map[i][j] = new NormalSquare(i, j); map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; } } } //this is the start square, can be different then 0,0 -> depends on the map map[0][0] = new StartSquare(0, 0); map[0][0].Number = 1; //this is the final square, who goes there first wins the game -> again depends on the map map[mapHeight - 1][mapLength - 1] = new FinishSquare(mapHeight - 1, mapLength - 1); map[mapHeight - 1][mapLength - 1].Number = 100; return(map); }
public void GivenAKingThatStartsOn(string startSquare) { _piece = new King(Colour.Black); _startSquare = new StartSquare(startSquare); _board.PutPieceOn(_startSquare, _piece); }
public MapSection[][] GenerateFirstMap() { //map coordinates: const int mapHeight = 5; const int mapLength = 10; var map = new MapSection[mapHeight][]; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { map[i][j] = new NormalSquare(i, j); } } AddCoordinates(map); var mapSquares = new List <MapSection>(); var squareNumber = 1; var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { for (int j = 0; j < mapLength; j++) { if (i == 0 && j == 0) { map[i][j] = new StartSquare(i, j); } else if (i == map.Length - 1 && j == map[i].Length - 1) { map[i][j] = new FinishSquare(i, j); } else if (bonusCounter > 6) { if ((counter / 2 + bonusCounter) % 2 == 0) { map[i][j] = new BonusSquare(i, j); } else { map[i][j] = new MysterySquare(i, j); } bonusCounter = 0; } else if (counter > 5 && (bonusCounter + 1) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter = 1; } else if (counter > 5) { map[i][j] = new GoBackSquare(i, j); counter = 1; } else { map[i][j] = new NormalSquare(i, j); } map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; AddCoordinates(map); mapSquares.Add(map[i][j]); if (squareNumber == 51) { break; } } } var json = Serializer.ExportFirstMapCoordinates(mapSquares); Console.WriteLine(json); return(map); }
public static List <MapSection> GetMapPath() { //Used for the map path service const int mapHeight = 5; const int mapLength = 10; var map = new MapSection[mapHeight][]; for (int i = 0; i < mapHeight; i++) { map[i] = new MapSection[mapLength]; for (int j = 0; j < mapLength; j++) { map[i][j] = new NormalSquare(i, j); } } AddCoordinates(map); var mapSquares = new List <MapSection>(); var squareNumber = 1; var counter = 0; var bonusCounter = 0; for (int i = 0; i < mapHeight; i++) { for (int j = 0; j < mapLength; j++) { if (i == 0 && j == 0) { map[i][j] = new StartSquare(i, j); } else if (i == map.Length - 1 && j == map[i].Length - 1) { map[i][j] = new FinishSquare(i, j); } else if (bonusCounter > 6) { if ((counter / 2 + bonusCounter) % 2 == 0) { map[i][j] = new BonusSquare(i, j); } else { map[i][j] = new MysterySquare(i, j); } bonusCounter = 0; } else if (counter > 5 && (bonusCounter + 1) % 2 == 0) { map[i][j] = new GoForwardSquare(i, j); counter = 1; } else if (counter > 5) { map[i][j] = new GoBackSquare(i, j); counter = 1; } else { map[i][j] = new NormalSquare(i, j); } map[i][j].Number = squareNumber; squareNumber++; counter++; bonusCounter++; AddCoordinates(map); mapSquares.Add(map[i][j]); if (squareNumber == 51) { break; } } } return(mapSquares); }