/// <summary> /// Find all possible Moves of a Chesspiece in position of a State /// </summary> /// <param name="arrState"></param> /// <param name="pos"></param> /// <returns></returns> public static ArrayList FindAllPosibleMoves(ChessState[,] arrState, Point pos, eChessSide ownside) { ArrayList arrMove = new ArrayList(); switch (arrState[pos.X, pos.Y].Type) { case eChessPieceType.Bishop: arrMove = ChessPiece_Bishop.FindAllPosibleMoves(arrState, pos); break; case eChessPieceType.King: arrMove = ChessPiece_King.FindAllPosibleMoves(arrState, pos, ownside); break; case eChessPieceType.Knight: arrMove = ChessPiece_Knight.FindAllPosibleMoves(arrState, pos); break; case eChessPieceType.Pawn: arrMove = ChessPiece_Pawn.FindAllPosibleMoves(arrState, pos, ownside); break; case eChessPieceType.Queen: arrMove = ChessPiece_Queen.FindAllPosibleMoves(arrState, pos); break; case eChessPieceType.Rook: arrMove = ChessPiece_Rook.FindAllPosibleMoves(arrState, pos); break; } if (arrMove.Count == 0) { return(arrMove); } ArrayList arr_CanMoves = new ArrayList(); ChessState[,] NewState = new ChessState[10, 10]; for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { NewState[i, j] = new ChessState(arrState[i, j].Type, arrState[i, j].Side, arrState[i, j].Moves); } } foreach (ChessMove m in arrMove) { //If one move that makes king will be checked -> remove PredictMove(NewState, m); if (Checked(NewState, arrState[pos.X, pos.Y].Side, ownside) == false) { arr_CanMoves.Add(m); } UnPredictMove(NewState, m); } return(arr_CanMoves); }
public static ChessMove MakeAComputerMove(ChessState[,] arrState, eChessSide side, Dictionary <string, int> arrPosition, eGameDifficulty difficult, eChessSide ownside) { _myBestMove = null; _myBestScore = _lowestScore; if (difficult == eGameDifficulty.Hard) { _maxDepth = 5; } else if (difficult == eGameDifficulty.Normal) { _maxDepth = 4; } else { _maxDepth = 3; } _mySide = side; _opSide = eChessSide.Black; if (_mySide == eChessSide.Black) { _opSide = eChessSide.White; } _ownSide = ownside; if (FindAllPosibleMoves(arrState, _mySide, _ownSide).Count + FindAllPosibleMoves(arrState, _opSide, _ownSide).Count < 30) { _maxDepth = 5; } ChessState[,] NewState = new ChessState[10, 10]; for (int i = 0; i <= 9; i++) { for (int j = 0; j <= 9; j++) { NewState[i, j] = new ChessState(arrState[i, j].Type, arrState[i, j].Side, arrState[i, j].Moves); } } AlphaBeta(NewState, arrPosition, _maxDepth, _mySide, _lowestScore, -_lowestScore); /* * PredictMove(NewState, _myBestMove); * if (Checked(NewState, _mySide) == false) * return _myBestMove; * * return RandomMove(State,side);*/ return(_myBestMove); }
public Save_Load_ChessBoard(Uc_ChessBoard board, Uc_CountDownTimer timer1, Uc_CountDownTimer timer2) { //Save Chess Board this.SaveThisState = new ChessState[10, 10]; int i, j; for (i = 0; i < 10; i++) { for (j = 0; j < 10; j++) { SaveThisState[i, j] = new ChessState(board.arrState[i, j].Type, board.arrState[i, j].Side, board.arrState[i, j].Moves); } } this.GameStatus = board.GameStatus; this.GameStatusReason = board.GameStatusReason; this.WhoTurn = board.WhoTurn; this.arrWhoCheck = board.arrWhoCheck; this.stkUndo = board.stkUndo; this.stkRedo = board.stkRedo; this.stkChessMoveString = board.stkChessMoveString; this.stkChessPieceEated = board.stkChessPieceEated; this.clear_Stack_Redo = board.clear_Stack_Redo; this.PositionLastMove = new Point(Uc_ChessBoard.PositionLastMove.X, Uc_ChessBoard.PositionLastMove.Y); this.PositionChoosen = new Point(board.PositionChoosen.X, board.PositionChoosen.Y); this.arrPosition = board.arrPosition; this.OwnSide = board.OwnSide; this.GameMode = board.GameMode; this.GameDifficulty = board.GameDifficulty; //Save Timer this.Min1 = timer1.Min; this.Sec1 = timer1.Sec; this.Min2 = timer2.Min; this.Sec2 = timer2.Sec; }