/// <summary> /// Generates the next possible moves on the current board. There is no depth or ply to these moves /// </summary> /// <param name="currentBoard">board to analize</param> /// <param name="AiTurn">Whether it is the AI's turn or the players</param> /// <returns>A list of moves which are possible this turn</returns> public static List <Move> GenerateNextMoves(char[] currentBoard, bool AiTurn) { List <Move> movesQueue = new List <Move>(); List <int> myPieces; if (AiTurn) { myPieces = BoardManager.GetTeamPieceIndexes(currentBoard, GameManager.Instance.aiTeam); } else { myPieces = BoardManager.GetTeamPieceIndexes(currentBoard, GameManager.Instance.playerTeam); } foreach (int pieceIndex in myPieces) { List <int> possibleMoves = MoveValidator.FindValidMoves(pieceIndex, currentBoard); foreach (int move in possibleMoves) { movesQueue.Add(new Move(currentBoard, pieceIndex, move)); } } return(movesQueue = Prioritize(movesQueue, AiTurn)); }
/// <summary> /// Picks up a piece on the board /// </summary> void TryPickup() { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit) && hit.transform.tag == "chessPiece") { heldPiece = hit.transform.GetComponent <PieceScript>(); if (heldPiece.team == GameManager.Instance.playerTeam) { ClearValidMoves(); List <int> moves = MoveValidator.FindValidMoves(BoardManager.PositionToBoardIndex(hit.transform.position), BoardManager.BoardToCharArray(board)); for (int i = 0; i < moves.Count; i++) { validMoves.Add(board[moves[i]]); } ApplyHighlight(); } else { heldPiece = null; } } }