static void Main(string[] args) { QuartoSearchTree tree = new QuartoSearchTree(); string[] board = { "B3", "B4", "D1", "C2", "D4", "A2", "A1", "B2", null, "B1", "A3", null, "C3", "D2", "A4", null }; Piece[] pieces = new Piece[MAXGAMEBOARD]; moveData move = new moveData(); pieces[0].setValues("A1", false); pieces[1].setValues("A2", false); pieces[2].setValues("A3", false); pieces[3].setValues("A4", false); pieces[4].setValues("B1", false); pieces[5].setValues("B2", false); pieces[6].setValues("B3", false); pieces[7].setValues("B4", false); pieces[8].setValues("C1", true); pieces[9].setValues("C2", false); pieces[10].setValues("C3", false); pieces[11].setValues("C4", true); pieces[12].setValues("D1", false); pieces[13].setValues("D2", false); pieces[14].setValues("D3", true); pieces[15].setValues("D4", false); move = tree.generateTree(board, 8, pieces, 3); }
public IEnumerator WaitForTurn(string lastTile, string onDeckPiece) { string[,] board = GameCoreController.Instance.GetBoard(); string[] newBoard = new string[board.Length]; AI.Piece[] pieces = new AI.Piece[GameCoreController.Instance.PieceNumberMap.Count]; int newBoardCounter = 0; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { newBoard[newBoardCounter] = board[i, j] == EMPTYSLOT ? null : board[i, j]; newBoardCounter++; } } intitializeAiPieceList(GameCoreController.Instance.GetPlayablePiecesList(), ref pieces, GameCoreController.Instance.PieceNumberMap); AI.moveData moveData = quartoAI.generateTree(2, newBoard, GameCoreController.Instance.PieceNumberMap[onDeckPiece], pieces); NextMove.OnDeckPiece = moveData.pieceToPlay; NextMove.Tile = moveData.lastMoveOnBoard; return(null); }
public IEnumerator AIThreadProcedure() { Debug.Log("AI thread is running..."); float startTime = Time.deltaTime; string[,] board = GameCoreController.Instance.GetBoard(); string[] newBoard = new string[board.Length]; AI.Piece[] pieces = new AI.Piece[GameCoreController.Instance.PieceNumberMap.Count]; int newBoardCounter = 0; for (int i = 0; i < board.GetLength(0); i++) { for (int j = 0; j < board.GetLength(1); j++) { newBoard[newBoardCounter] = board[i, j] == EMPTYSLOT ? null : board[i, j]; newBoardCounter++; } } intitializeAiPieceList(GameCoreController.Instance.GetPlayablePiecesList(), ref pieces, GameCoreController.Instance.PieceNumberMap); string onDeckPiece = GameCoreController.Instance.OnDeckPiece; int pieceToFind = GameCoreController.Instance.PieceNumberMap[onDeckPiece]; Task <AI.moveData> AITask = Task.Run(() => quartoAI.generateTree(newBoard, pieceToFind, pieces, difficulty)); while (AITask.Status != TaskStatus.RanToCompletion) { yield return(null); } if (Time.deltaTime - startTime < 1.0f) { yield return(new WaitForSeconds(1)); } AIMoveData = AITask.Result; }