예제 #1
0
        public void WhiteWinsOneMove()
        {
            StreamReader reader = new StreamReader(resourcesPath + "test4.json");
            Board        board  = Serializer <Board> .FromJson(reader.ReadToEnd());

            board.Initialize();
            AI.AIResult result = AI.FindBestMove(false, board, 0);
            board.MovePiece(result.move.piece, result.move.position);
            Assert.AreEqual(Winner.White, board.CheckEndCondition());
        }
예제 #2
0
    public IEnumerator AIMove(bool side)
    {
        yield return(new WaitForSeconds(1));

        //DateTime inicio = DateTime.Now;
        // Find best move
        AI.AIResult ai = AI.FindBestMove(side, model, 0);
        //Debug.Log((DateTime.Now - inicio).Minutes + ":" + (DateTime.Now - inicio).Seconds + "." + (DateTime.Now - inicio).Milliseconds);
        //Debug.Log("Leaves: " + ai.leaves + ", Value: " + ai.bestValue);

        // Find piece to move in placed pieces
        foreach (PieceObject po in piecesPool.Next <PieceObject>())
        {
            if (po.piece.Equals(ai.move.piece) && po.gameObject.activeSelf)
            {
                model.MovePiece(ai.move.piece, ai.move.position);
                audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
                Position newPos = model.GetPiecePosition(po.piece);
                po.SetHexPosition(ai.move.position.x, ai.move.position.y, ai.move.position.z);
                selectedPiece   = null;
                selectedUIPiece = null;
                break;
            }
        }

        // Find piece to move in the panel
        foreach (PiecesPanel panel in panels)
        {
            foreach (PieceUI pui in panel.pieces)
            {
                if (pui.piece.Equals(ai.move.piece))
                {
                    model.MovePiece(ai.move.piece, ai.move.position);
                    audioSource.PlayOneShot(soundArray[UnityEngine.Random.Range(0, soundArray.Length - 1)]);
                    GameObject instance = piecesPool.GetInstance(true);
                    instance.GetComponent <PieceObject>().Initialize(ai.move.piece, ClickDown);
                    instance.GetComponent <PieceObject>().SetHexPosition(model.GetPiecePosition(ai.move.piece));
                    panel.RemovePiece(pui);
                    selectedPiece   = null;
                    selectedUIPiece = null;
                    break;
                }
            }
        }

        selectedPiece   = null;
        selectedUIPiece = null;
        NextTurn();
    }