public void LogicPieceByLocationTesting() { ChessLogic logic = new ChessLogic(); var pawnPlaces = logic.FindPotentialPiecesForMove(PieceType.Pawn, new Position("C", "3")); Assert.AreEqual(pawnPlaces.Count, 1); }
public override List <Vector2Int> GetLegalMoves(Board boardState) { List <Vector2Int> AllowedMoves = new List <Vector2Int>(); AllowedMoves.AddRange(ChessLogic.GetAdjacent(boardState, index, distance)); return(AllowedMoves); }
public void LogicUndo() { ChessLogic logic = new ChessLogic(); ChessLogic logic2 = new ChessLogic(); ChessLogic logic3 = new ChessLogic(); logic.MovePiece(new Position("C", "2"), new Position("C", "4")); logic2.MovePiece(new Position("C", "2"), new Position("C", "4")); logic2.MovePiece(new Position("B", "8"), new Position("C", "6")); logic2.MovePiece(new Position("C", "4"), new Position("C", "5")); logic2.UndoMove(); logic3.MovePiece(new Position("C", "2"), new Position("C", "4")); logic3.MovePiece(new Position("B", "8"), new Position("C", "6")); Assert.AreEqual(logic2.Board.ToString(), logic3.Board.ToString()); logic2.UndoMove(); Assert.AreEqual(logic2.Board.ToString(), logic.Board.ToString()); bool invalidMove = logic2.IsMoveValid(new Position("C", "4"), new Position("C", "5")); Assert.AreEqual(invalidMove, false); logic2.MovePiece(new Position("B", "8"), new Position("C", "6")); Assert.AreEqual(logic2.Board.ToString(), logic3.Board.ToString()); logic2.MovePiece(new Position("C", "4"), new Position("C", "5")); logic2.UndoMove(); Assert.AreEqual(logic2.Board.ToString(), logic3.Board.ToString()); logic2.UndoMove(); Assert.AreEqual(logic2.Board.ToString(), logic.Board.ToString()); }
private GameManager(ICommandInterpreter commandInterpreter, ChessLogic logic, IMoveManager movementManager) { commandInterpreter.CommandReceived += CommandReceived; cmdInterpreter = commandInterpreter; chessLogic = logic; moveManager = movementManager; gameState = GameState.Ready; }
public void EnemyMoved(string originalPosition, string newPosition) { ChessDotNet.Player enemySide = Side == ChessDotNet.Player.White ? ChessDotNet.Player.Black : ChessDotNet.Player.White; SelectedCell = Cells.Single(item => item.Position == originalPosition); var move = new ChessDotNet.Move(originalPosition, newPosition, enemySide, 'Q'); var moveType = ChessLogic.MakeMove(move, true); UpdateSourceIfPromotion(moveType, newPosition, enemySide); SelectedCell.Source = null; UpdateSourceIfEnPassant(moveType, newPosition, enemySide); UpdateSourceIfCastling(moveType, newPosition); }
public bool GetInfo(string type, int x1, int y1, int x2, int y2) { //https://localhost:5001/Home/GetInfo?type=horse&x1=1&y1=2&x2=3&y2=4 return(type.ToLower() switch { "pawn" => ChessLogic.Pawn(x1, y1, x2, y2), "bishop" => ChessLogic.Bishop(x1, y1, x2, y2), "king" => ChessLogic.King(x1, y1, x2, y2), "queen" => ChessLogic.Queen(x1, y1, x2, y2), "knight" => ChessLogic.Knight(x1, y1, x2, y2), "rook" => ChessLogic.Rook(x1, y1, x2, y2), _ => false });
public void TestMoveComponentCompilation() { ChessLogic logic = new ChessLogic(); movePlanner = new MovePlanner(logic.Board); constructAnAxis(ref xMover, ref xCalibrator, ref xPreciseMover, ref xGridMover); constructAnAxis(ref yMover, ref yCalibrator, ref yPreciseMover, ref yGridMover); var magnet = new MockMagnet(); movePerformer = new MovePerformer(xGridMover, yGridMover, magnet); moveManager = new MoveManager(movePlanner, movePerformer); }
public static async Task <GameManager> CreateAsync() { var commandInterpreterConstructor = CommandInterpreter.CreateAsync(); ChessLogic logic = new ChessLogic(); var stepCountPinX = new GpioPinWrapper(5, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinX = new GpioPinWrapper(13, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationX = new MotorInformation(Axis.X, stepCountPinX); var motorDriverX = new MotorDrv(20, 21, motorInformationX); var motorLocatorX = new MotorLocator(stepClearPinX, motorDriverX.Information); var positionSignalerX = new PositionSignaler(motorLocatorX); var motorMoverX = new MotorMover(50, positionSignalerX, motorLocatorX, motorDriverX); var stepCountPinY = new GpioPinWrapper(6, Windows.Devices.Gpio.GpioPinDriveMode.InputPullUp); var stepClearPinY = new GpioPinWrapper(19, Windows.Devices.Gpio.GpioPinDriveMode.Output, Windows.Devices.Gpio.GpioPinValue.Low); var motorInformationY = new MotorInformation(Axis.Y, stepCountPinY); var motorDriverY = new MotorDrv(24, 23, motorInformationY); var motorLocatorY = new MotorLocator(stepClearPinY, motorDriverY.Information); var positionSignalerY = new PositionSignaler(motorLocatorY); var motorMoverY = new MotorMover(50, positionSignalerY, motorLocatorY, motorDriverY); var topInterrupterX = new PhotoInterrupter(17, 1, 150); var bottomInterrupterX = new PhotoInterrupter(27, -1, -150); var motorCalibratorX = new MotorCalibrator(-23, 23, motorMoverX, motorInformationX, topInterrupterX, bottomInterrupterX); var topInterrupterY = new PhotoInterrupter(25, 1, 150); var bottomInterrupterY = new PhotoInterrupter(22, -1, -150); var motorCalibratorY = new MotorCalibrator(-17, 17, motorMoverY, motorInformationY, topInterrupterY, bottomInterrupterY); var preciseMoverX = new PreciseMotorMover(motorMoverX); var gridMoverX = new GridMotorMover(preciseMoverX, motorCalibratorX); var preciseMoverY = new PreciseMotorMover(motorMoverY); var gridMoverY = new GridMotorMover(preciseMoverY, motorCalibratorY); var magnetDriver = new MagnetDrv(26); var movePerformer = new MovePerformer(gridMoverX, gridMoverY, magnetDriver); var motorCalibrationTask = movePerformer.CalibrateAsync(); var movePlanner = new MovePlanner(logic.Board); var moveManager = new MoveManager(movePlanner, movePerformer); GameManager manager = new GameManager(await commandInterpreterConstructor, logic, moveManager); await motorCalibrationTask; #if DEBUG manager.DebugMovePerformer = movePerformer; #endif return(manager); }
public override List <Vector2Int> GetLegalMoves(Board boardState) { List <Vector2Int> movesToCheck = new List <Vector2Int>(); movesToCheck.Add(index + new Vector2Int(-1, 2)); movesToCheck.Add(index + new Vector2Int(1, 2)); movesToCheck.Add(index + new Vector2Int(2, 1)); movesToCheck.Add(index + new Vector2Int(2, -1)); movesToCheck.Add(index + new Vector2Int(1, -2)); movesToCheck.Add(index + new Vector2Int(-1, -2)); movesToCheck.Add(index + new Vector2Int(-2, -1)); movesToCheck.Add(index + new Vector2Int(-2, 1)); return(ChessLogic.CheckSpots(boardState, index, movesToCheck)); }
public void LogicMoveTesting() //test against move that already exsists in chessboard { ChessLogic logic = new ChessLogic(); ChessBoard board = new ChessBoard(); Assert.AreEqual(logic.Board.ToString(), board.ToString()); logic.MovePiece(new Position("C", "2"), new Position("C", "4")); board.MovePiece(new Position("C", "2"), new Position("C", "4")); Assert.AreEqual(logic.Board.ToString(), board.ToString()); logic.MovePiece(new Position("B", "8"), new Position("C", "6")); board.MovePiece(new Position("B", "8"), new Position("C", "6")); Assert.AreEqual(logic.Board.ToString(), board.ToString()); //logic.MovePiece(new Position("C", "4"), new Position("C", "4")); //threw appropriate exception //board.MovePiece(new Position("C", "4"), new Position("C", "4")); Assert.AreEqual(logic.Board.ToString(), board.ToString()); //Assert.AreEqual(logic.Board.ToString(), "a"); //display board }
public override List <Vector2Int> GetLegalMoves(Board boardState) { List <Vector2Int> AllowedMoves = new List <Vector2Int>(); //Basic Moves List <Vector2Int> moveSpots = new List <Vector2Int>(); moveSpots.AddRange(ChessLogic.GetAdjacent(boardState, index, distance)); //Debug.Log(moveSpots.Count + " Potential Adjacent Moves Found"); for (int i = 0; i < moveSpots.Count; i++) { //If it would be a capture, remove it. Pawns Can't capture adjacent if (boardState.boardState[moveSpots[i].x, moveSpots[i].y].chessPiece == null) { AllowedMoves.Add(moveSpots[i]); } } //Debug.Log(moveSpots.Count + " Legal Adjacent Moves Found"); //Attacks on Diagonals List <Vector2Int> attackSpots = new List <Vector2Int>(); attackSpots.AddRange(ChessLogic.GetDiagonals(boardState, index, 1)); for (int i = 0; i < attackSpots.Count; i++) { //If it would be a move, not a capture, remove it. Pawns can't move diagonal if (boardState.boardState[attackSpots[i].x, attackSpots[i].y].chessPiece != null) { AllowedMoves.Add(attackSpots[i]); } } //En Passant? // Should This be added? // return(AllowedMoves); }
public void LogicCastleTesting() { ChessLogic logic = new ChessLogic(); logic.MovePiece(new Position("E", "2"), new Position("E", "4")); logic.MovePiece(new Position("D", "7"), new Position("D", "6")); logic.MovePiece(new Position("G", "1"), new Position("F", "3")); logic.MovePiece(new Position("C", "8"), new Position("E", "6")); logic.MovePiece(new Position("F", "1"), new Position("D", "3")); logic.MovePiece(new Position("B", "8"), new Position("C", "6")); logic.MovePiece(new Position("E", "1"), new Position("E", "2")); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!! About to get rook for Black Castle Kingside"); var rookPos = logic.validRookLocationsForCastling(); //TODO: this is the problem line System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!! About to Black Castle Kingside with rook at " + rookPos[0]); logic.Castle(rookPos[0]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!! About to get rook for White Castle Queenside"); rookPos = logic.validRookLocationsForCastling(); System.Diagnostics.Debug.WriteLine("!!!!!!!!!!!! About to White Castle Queenside"); logic.Castle(rookPos[0]); }
public async Task VisualizerTest1() { ChessLogic logic = new ChessLogic(); MovePlanner planner = new MovePlanner(logic.Board); MovePerformerVisualizer visualizer = new MovePerformerVisualizer(); MoveManager manager = new MoveManager(planner, visualizer); visualizer.ResetBoardRep(); visualizer.PrintBoardRep(); List <Position[]> moves = new List <Position[]>(); Position[] move = new Position[2]; //can't reuse move like that, apparently move[0] = new Position("E", "2"); move[1] = new Position("E", "4"); moves.Add(move); foreach (var movement in moves) { logic.IsMoveValid(movement[0], movement[1]); await manager.MoveAsync(movement[0], movement[1]); logic.MovePiece(movement[0], movement[1]); } }
public bool CheckStep(string arg) => ChessLogic.CheckStep(arg);
public Point[] GetMoves(Point location) { ChessPiece piece = board[location.X, location.Y]; return(ChessLogic.GetMoves(piece, location, board)); }
/// <summary> /// 初始化局面 /// </summary> /// <param name="chessLogic"></param> public void Init(ChessLogic chessLogic) { logic = chessLogic; }
public async Task VisualizerTest3BasicUndo() { ChessLogic logic = new ChessLogic(); MovePlanner planner = new MovePlanner(logic.Board); MovePerformerVisualizer visualizer = new MovePerformerVisualizer(); MoveManager manager = new MoveManager(planner, visualizer); visualizer.ResetBoardRep(); visualizer.PrintBoardRep(); List <Position[]> moves = new List <Position[]>(); Position[] move1 = new Position[2]; move1[0] = new Position("E", "2"); move1[1] = new Position("E", "4"); moves.Add(move1); Position[] move2 = new Position[2]; move2[0] = new Position("D", "7"); move2[1] = new Position("D", "5"); moves.Add(move2); Position[] move3 = new Position[2]; move3[0] = new Position("G", "1"); move3[1] = new Position("F", "3"); moves.Add(move3); Position[] move4 = new Position[2]; move4[0] = new Position("C", "8"); move4[1] = new Position("E", "6"); moves.Add(move4); Position[] move5 = new Position[2]; move5[0] = new Position("F", "1"); move5[1] = new Position("C", "4"); moves.Add(move5); Position[] move6 = new Position[2]; move6[0] = new Position("B", "8"); move6[1] = new Position("C", "6"); moves.Add(move6); Position[] move7 = new Position[2]; move7[0] = new Position("E", "1"); move7[1] = new Position("E", "2"); moves.Add(move7); Position[] move8 = new Position[2]; move8[0] = new Position("D", "5"); move8[1] = new Position("E", "4"); moves.Add(move8); Position[] move9 = new Position[2]; move9[0] = new Position("C", "4"); move9[1] = new Position("E", "6"); moves.Add(move9); Position[] move10 = new Position[2]; move10[0] = new Position("E", "4"); move10[1] = new Position("F", "3"); moves.Add(move10); Position[] move11 = new Position[2]; move11[0] = new Position("A", "2"); move11[1] = new Position("A", "3"); moves.Add(move11); Position[] move12 = new Position[2]; move12[0] = new Position("F", "7"); move12[1] = new Position("E", "6"); moves.Add(move12); Position[] move13 = new Position[2]; move13[0] = new Position("E", "2"); move13[1] = new Position("F", "3"); moves.Add(move13); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); foreach (var movement in moves) { System.Diagnostics.Debug.WriteLine(movement[0].ToString() + "\t" + movement[1].ToString()); Assert.AreEqual(logic.IsMoveValid(movement[0], movement[1]), true); await manager.MoveAsync(movement[0], movement[1]); logic.MovePiece(movement[0], movement[1]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); } System.Diagnostics.Debug.WriteLine("Black castles kingside."); var rookLocationForBlackCastle = logic.validRookLocationsForCastling(); Assert.AreEqual(rookLocationForBlackCastle.Count, 1); await manager.CastleAsync(rookLocationForBlackCastle[0], logic.Board.GetKingCol()); logic.Castle(rookLocationForBlackCastle[0]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); System.Diagnostics.Debug.WriteLine("White castles queenside."); var rookLocationForWhiteCastle = logic.validRookLocationsForCastling(); Assert.AreEqual(rookLocationForWhiteCastle.Count, 1); await manager.CastleAsync(rookLocationForWhiteCastle[0], logic.Board.GetKingCol()); logic.Castle(rookLocationForWhiteCastle[0]); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); for (int i = 0; i < moves.Count + 2; i++) //+2 for the two castles { await manager.UndoMoveAsync(); logic.UndoMove(); System.Diagnostics.Debug.WriteLine(logic.Board.ToString()); } }
public ActionResult <Game> Move(string playerId, string gameCode, string fromPos, string toPos) { ChessLogic chessLogic = new ChessLogic(); Game game = games.Where(g => g.Code == gameCode).FirstOrDefault(); if (game == null) { return(NotFound(new { ErrorMsg = "Invalid game code: " + gameCode })); } if (game.IsWhiteTurn && game.PlayerIdWhite != playerId) { return(game); } if (!game.IsWhiteTurn && game.PlayerIdBlack != playerId) { return(game); } State state = chessLogic.Controller(fromPos, toPos); if (state != State.ImpossibleMove) { game.IsWhiteTurn = !game.IsWhiteTurn; int startRow = int.Parse(fromPos[1].ToString()) - 1; int startCol = 7 - ((int)fromPos[0] - 97); int finalRow = int.Parse(toPos[1].ToString()) - 1; int finalCol = 7 - ((int)toPos[0] - 97); string move = game.Chessboard[startRow][startCol] + toPos; game.Moves.Add(move); game.Chessboard[finalRow][finalCol] = game.Chessboard[startRow][startCol]; game.Chessboard[startRow][startCol] = ' '; game.NumberOfMoves++; } switch (state) { case State.WhiteIsMate: game.StateAfterFinish = State.WhiteIsMate; break; case State.BlackIsMate: game.StateAfterFinish = State.BlackIsMate; break; case State.Draw: game.StateAfterFinish = State.Draw; break; case State.ImpossibleMove: game.StateAfterFinish = State.ImpossibleMove; break; case State.CorrectMove: game.StateAfterFinish = State.CorrectMove; break; default: break; } return(game); }
public Search(ChessLogic c, Situation s) { situation = s; chessLogic = c; }
public bool Check(string piece, string from0, string to0) { return(ChessLogic.Check(piece, from0, to0)); }