コード例 #1
0
ファイル: AiMoveTests.cs プロジェクト: Tanzgarnele/TicTacToe
        public void GetAiHardPointIndex_MiniMaxToPointIndex_()
        {
            Mock <IMatrixAlgorithm> algorithm = new Mock <IMatrixAlgorithm>();

            PlayerType[,] board = new PlayerType[3, 3]
            {
                { PlayerType.O, PlayerType.X, PlayerType.O },
                { PlayerType.X, PlayerType.X, PlayerType.Unassigned },
                { PlayerType.X, PlayerType.O, PlayerType.O }
            };

            algorithm
            .Setup(x => x.Board)
            .Returns(board);
            algorithm
            .Setup(x => x.CurrentTurn)
            .Returns(PlayerType.O);
            algorithm
            .Setup(x => x.BoardSize)
            .Returns(3);

            AiMove localInstance = this.CreateInstance();

            PointIndex actual = localInstance.GetAiHardPointIndex(algorithm.Object);

            PointIndex expected = localInstance.BestPointMove;

            Assert.That(() => actual, Is.EqualTo(expected));
        }
コード例 #2
0
ファイル: TurnManager.cs プロジェクト: rgo594/BFSTRPG
    public static void AddNpcUnit(AiMove unit)
    {
        List <AiMove> list;

        ;
        if (!teamUnits.ContainsKey(unit.tag))
        {
            list = new List <AiMove>();

            //add list value to key (currently will be null instead of empty list). ex. {"Enemy" : [] }
            teamUnits[unit.tag] = list;

            if (!teamPhaseOrder.Contains(unit.tag))
            {
                //adds team to phase order
                teamPhaseOrder.Enqueue(unit.tag);
            }
        }
        else
        {
            //makes the list variable equal the value of a team key (which is a tag like "Enemy") in the teamUnits dictionary. ex. teamUnits = {"Enemy" : [] } list = [] <-- same list as the value of "Enemy"
            list = teamUnits[unit.tag];
        }

        //adds unit to teams unit list {"Enemy" : [ NPC ] }
        list.Add(unit);
    }
コード例 #3
0
 private void SetMovesForAllies(Color color)
 {
     for (int i = 0; i < TempGameBoard.Count; i++)
     {
         if (TempGameBoard[i].PieceColor == color)
         {
             AiMove.SetMovementList(TempGameBoard[i], TempGameBoard);
         }
     }
 }
コード例 #4
0
        // eftersom ennemy inte har några moves, så får dom de här!

        private void SetMovesForEnemiesInList(Pieces piece)
        {
            foreach (var enemie in TempGameBoard)
            {
                if (enemie.PieceColor != piece.PieceColor)
                {
                    AiMove.SetMovementList(enemie, TempGameBoard);
                }
            }
        }
コード例 #5
0
ファイル: PlayerMove.cs プロジェクト: rgo594/BFSTRPG
    public IEnumerator AttackAction()
    {
        yield return(new WaitUntil(() => TurnManager.attackStep == true));

        Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit2D hit = Physics2D.Raycast(ray.origin, Vector2.up);


        foreach (TileFunctions enemyTile in detectedEnemies)
        {
            AiMove enemyMove = enemyTile.detectedEnemy.gameObject.GetComponent <AiMove>();

            if (Input.GetMouseButtonUp(0))
            {
                if (hit.collider.gameObject == enemyTile.detectedEnemy.gameObject)
                {
                    targetedEnemy = enemyTile.detectedEnemy.gameObject;

                    Vector3 enemyPos  = targetedEnemy.transform.position;
                    Vector3 playerPos = gameObject.transform.position;

                    Animator animator = gameObject.GetComponent <Animator>();

                    attacking = true;
                    if (enemyPos.x > playerPos.x)
                    {
                        animator.SetTrigger("AttackRight");
                    }
                    else if (enemyPos.x < playerPos.x)
                    {
                        animator.SetTrigger("AttackLeft");
                    }
                    else if (enemyPos.y > playerPos.y)
                    {
                        animator.SetTrigger("AttackUp");
                    }
                    else if (enemyPos.y < playerPos.y)
                    {
                        animator.SetTrigger("AttackDown");
                    }
                    ToggleUnitMenu(false);
                }
            }
        }
    }
コード例 #6
0
        private bool CanIThreatenTheKing(Move possibleMove, Pieces piece)
        {
            var testPiece = GetPieceFromTempBoard(piece);

            testPiece.CurrentPosition._PosX = possibleMove.endPositions._PosX;
            testPiece.CurrentPosition._PosY = possibleMove.endPositions._PosY;

            AiMove.SetMovementList(testPiece, TempGameBoard);

            foreach (var move in testPiece.ListOfMoves)
            {
                if (CompareEnemyPositionToMyMove(GetPositionOfEnemyKing(), move))
                {
                    RestoreTempGameBoard();
                    return(false);
                }
            }
            RestoreTempGameBoard();
            return(false);
        }
コード例 #7
0
        private bool WillIthreaten(Pieces piece, Move move)
        {
            Pieces tempPiece = GetPieceFromTempBoard(piece);



            tempPiece.CurrentPosition = new Point(move.endPositions._PosX, move.endPositions._PosY);
            AiMove.SetMovementList(tempPiece, TempGameBoard);

            foreach (Move tempMove in tempPiece.ListOfMoves)
            {
                if (CanItakeSomething(tempMove))
                {
                    RestoreTempGameBoard();
                    return(true);
                }
            }

            RestoreTempGameBoard();
            return(false);
        }
コード例 #8
0
 protected void OnAiMove()
 {
     AiMove?.Invoke(this, new EventArgs());
 }
コード例 #9
0
ファイル: Logic.cs プロジェクト: David37/TicTacToe
        private Point Hard()//AI choses the best location for its shape that will either garuantee a win or a draw
        {
            AiMove bestmovee = BestMove(CurrentGame, 1);

            return(new Point(bestmovee.x, bestmovee.y));
        }