예제 #1
0
        //[TestCase(1, 0, 7, 1)]
        public void BestResponseTest(int x1, int y1, int x2, int y2)
        {
            // Arrange
            bool player1    = true;
            var  board      = new Board(player1);
            var  boardLogic = new BoardLogic(player1);
            var  AI         = new ArtificialIntelligence(board);

            Move expected = new Move();

            expected.x1 = x1;
            expected.x2 = x2;
            expected.y1 = y1;
            expected.y2 = y2;

            // Act

            //board.FinallyMove(x1, y1, x2, y2);
            Move result = AI.BestResponse(board, boardLogic);

            // Assert
            Assert.AreEqual(result.x1, expected.x1);// no se por qué no toma como iguales a result y expected, pero asi separados por componentes sí.
            Assert.AreEqual(result.y1, expected.y1);
            Assert.AreEqual(result.x2, expected.x2);
            Assert.AreEqual(result.y2, expected.y2);
        }
예제 #2
0
    public void DecrementPopulation(GameObject _HomeWorld, string tagCopy)
    {
        if (transform.tag != tagCopy)
        {
            WorldPopulation--;
            if (WorldPopulation < 0)
            {
                ArtificialIntelligence aiScript = gameObject.GetComponent <ArtificialIntelligence>();
                if (aiScript)
                {
                    Destroy(aiScript);
                }

                ChangeAllegiance(_HomeWorld);
                //give ai powers
                if (Tag != "Red")
                {
                    gameObject.AddComponent <ArtificialIntelligence>();
                }
            }
        }
        if (transform.tag == tagCopy)
        {
            WorldPopulation++;
        }
    }
예제 #3
0
 /// <summary>
 /// Move checker for real
 /// </summary>
 public void Do()
 {
     Checker.Cell.Clear();
     Game.Unselect();
     Checker.Cell = ToCell;
     Checker.ClearMoves();
     if (Killed != null)
     {
         foreach (Checker killedChecker in Killed)
         {
             killedChecker.Kill();
         }
     }
     if (Game.CheckEndOfGame())
     {
         return;
     }
     ComputeAllowedMoves();
     if (IsExistMoveWithKill())
     {
         ClearMovesWithoutCills();
     }
     if (SetQueen)
     {
         Checker.BeQueen();
     }
     if (!Game.VsCpu)
     {
         Game.IsWhite = !Game.IsWhite;
     }
     else
     {
         ArtificialIntelligence.Move();
     }
 }
예제 #4
0
        public AIStateWandering(ArtificialIntelligence brains)
            : base(brains)
        {
            _transitions.Add(EAIState.Alert, () =>
                             Debug.Log("Zombie::???????"));

            _ownerBrain = (WarriorBrains)brains;
        }
 // Use this for initialization
 void Awake()
 {
     gameManager = GameObject.FindGameObjectWithTag("GameController").GetComponent <GameManager>();
     selectionCircle.SetActive(false);
     agent = GetComponent <NavMeshAgent>();
     artificialIntelligence = GetComponent <ArtificialIntelligence>();
     anim   = GetComponent <Animator>();
     target = null;
 }
 void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != null)
     {
         DestroyImmediate(this.gameObject);
     }
 }
예제 #7
0
        public Playing(GameModel gameModel, Vehicle car)
        {
            this.gameModel = gameModel;

            drawer               = new Drawer2D();
            velocimeter          = new CustomSprite();
            velocimeter.Bitmap   = new CustomBitmap(MediaDir + "GUI\\HUB\\Velocimetro\\VelocimetroSinFlecha.png", D3DDevice.Instance.Device);
            velocimeter.Position = new TGCVector2(D3DDevice.Instance.Width * 0.84f, D3DDevice.Instance.Height * 0.70f);
            velocimeter.Scaling  = new TGCVector2(0.2f, 0.2f);

            arrowVelocimeter                = new CustomSprite();
            arrowVelocimeter.Bitmap         = new CustomBitmap(MediaDir + "GUI\\HUB\\Velocimetro\\Flecha.png", D3DDevice.Instance.Device);
            arrowVelocimeter.Position       = new TGCVector2(D3DDevice.Instance.Width * 0.915f, D3DDevice.Instance.Height * 0.85f);
            arrowVelocimeter.Scaling        = new TGCVector2(0.2f, 0.2f);
            arrowVelocimeter.RotationCenter = new TGCVector2(0, arrowVelocimeter.Bitmap.Height / 8);
            arrowVelocimeter.Rotation       = -FastMath.PI;

            barOfLifeGreen          = new CustomSprite();
            barOfLifeGreen.Bitmap   = new CustomBitmap(MediaDir + "GUI\\HUB\\BarraDeVida\\1.jpg", D3DDevice.Instance.Device);
            barOfLifeGreen.Position = new TGCVector2(D3DDevice.Instance.Width * 0.80f, D3DDevice.Instance.Height * 0.95f);
            barOfLifeGreen.Scaling  = new TGCVector2(0.05f, 0.05f);

            barOfLifeRed          = new CustomSprite();
            barOfLifeRed.Bitmap   = new CustomBitmap(MediaDir + "GUI\\HUB\\BarraDeVida\\2.jpg", D3DDevice.Instance.Device);
            barOfLifeRed.Position = new TGCVector2(D3DDevice.Instance.Width * 0.80f, D3DDevice.Instance.Height * 0.95f);
            barOfLifeRed.Scaling  = new TGCVector2(0.07f, 0.05f);

            this.camaraInterna = new ThirdPersonCamera(camaraDesplazamiento, 0.8f, -33);
            //this.camaraManagement = new CamaraEnTerceraPersona(camaraDesplazamiento, 3f, -50);
            this.gameModel.Camara = camaraInterna;
            //this.auto = new Van(new TGCVector3(-60f, 0f, 0f), new SoundsManager());
            this.auto = car;
            auto.ResetScale();
            //this.auto.mesh.D3dMesh.ComputeNormals();
            listener = this.auto.mesh.clone("clon");
            this.gameModel.DirectSound.ListenerTracking = listener;
            Scene.GetInstance().SetVehiculo(this.auto);
            this.AI = new ArtificialIntelligence(new TGCVector3(70f, 0f, 0f), new SoundsManager());
            Scene.GetInstance().AI = this.AI;
            Scene.GetInstance().SetCamera(camaraInterna);
            this.auto.SoundsManager.AddSound(this.auto.GetPosition(), 50f, -500, "BackgroundMusic\\Burn.wav", "YouCouldBeMine", false);
            this.auto.SoundsManager.GetSound("YouCouldBeMine").play(true);

            /*var aspectRatio = D3DDevice.Instance.AspectRatio;
             * TGCMatrix view = TGCMatrix.LookAtLH(gameModel.Camara.Position, gameModel.Camara.LookAt, gameModel.Camara.UpVector);
             * TGCMatrix proj = TGCMatrix.PerspectiveFovLH(Geometry.DegreeToRadian(360), aspectRatio, 0, 1);
             * this.gameModel.Frustum.updateVolume(view, proj);
             * D3DDevice.Instance.Device.Transform.View = view;
             * D3DDevice.Instance.Device.Transform.Projection = proj;
             */

            this.Update();
        }
예제 #8
0
 /// <summary>
 /// Initialize variables
 /// </summary>
 private static void Initialize(Color playerColor, bool vsCpu)
 {
     VsCpu = vsCpu;
     if (vsCpu)
     {
         ArtificialIntelligence.Initialize(playerColor == Color.White);
     }
     GameDataHandler.WhiteCheckers = new List <WhiteChecker>();
     GameDataHandler.BlackCheckers = new List <BlackChecker>();
     GameDataHandler.PreviousMoves = new List <Move>();
     IsWhite = true;
     GameDataHandler.CurrentMoveIndex = 0;
 }
예제 #9
0
        public GameViewModel(ArtificialIntelligence ai, Tetris game)
        {
            AI             = ai;
            Game           = game;
            Game.GameSpeed = 10;

            for (int x = 0; x < 10; x++)
            {
                CellList.Add(new ObservableCollection <Cell>());
                for (int y = 21; y >= 0; y--)
                {
                    CellList[x].Add(Game.Matrix[x, y]);
                }
            }
        }
예제 #10
0
        public void EvaluateBoardTest(int EvaluateExpected, int x1, int y1, int x2, int y2)
        {
            // Arrange
            bool player1    = true;
            var  board      = new Board(player1);
            var  boardLogic = new BoardLogic(player1);
            var  AI         = new ArtificialIntelligence(board);

            // Act
            boardLogic.TurnChange(board);
            boardLogic.LogicMove(x1, y1, x2, y2, board);
            var result = AI.EvaluateBoard(board);

            // Assert
            Assert.AreEqual(EvaluateExpected, result);
        }
예제 #11
0
 public Desk(int width, int height, int rotation, bool currentWhiteTurn, bool firstPlayerIsHuman, bool secondPlayerIsHuman)
 {
     Width            = width > MinWidth ? width : MinWidth;
     Height           = height > MinHeight ? height : MinHeight;
     Rotation         = rotation;
     CurrentWhiteTurn = currentWhiteTurn;
     if (!firstPlayerIsHuman)
     {
         _firstPlayerBot = new ArtificialIntelligence(CurrentWhiteTurn);
     }
     if (!secondPlayerIsHuman)
     {
         _secondPlayerBot = new ArtificialIntelligence(!CurrentWhiteTurn);
     }
     FirstPlayer  = new Player(firstPlayerIsHuman, CurrentWhiteTurn);
     SecondPlayer = new Player(secondPlayerIsHuman, !CurrentWhiteTurn);
     OrganizeDefaultPositions();
 }
예제 #12
0
 /// <summary>
 /// Ход бота
 /// </summary>
 private void BotMove()
 {
     var nextPoint = ArtificialIntelligence.GetNextPoint(_player);
     if (_player.Field[nextPoint.Y, nextPoint.X] == CellType.Ship)
     {
         OnShot(nextPoint.X, nextPoint.Y, PlayerType.Player);
         if (_player.Lose())
         {
             //MessageBox.Show(@"Вы проиграли!");
             ClearGame();
             OnEndGame(PlayerType.Pc);
             return;
         }
         BotMove();
     }
     else
     {
         OnShot(nextPoint.X, nextPoint.Y, PlayerType.Player);
         _aiMove = false;
     }
 }
예제 #13
0
        public void Play(IFixture fixture, IDictionary <int, Player> homeTeamFormation, IDictionary <int, Player> awayTeamFormation, Action <double, double[, ]> updateUi)
        {
            if (fixture.TeamHome.TeamName == Configuration.PlayerTeamName)
            {
                ArtificialIntelligence.SelectStartingFormation(awayTeamFormation, fixture.TeamAway, fixture.TeamHome);
                awayTeamFormation.Values.Execute(p => p.Location.Invert());
            }
            else if (fixture.TeamAway.TeamName == Configuration.PlayerTeamName)
            {
                ArtificialIntelligence.SelectStartingFormation(homeTeamFormation, fixture.TeamHome, fixture.TeamAway);
            }
            else
            {
                ArtificialIntelligence.SelectStartingFormation(homeTeamFormation, fixture.TeamHome, fixture.TeamAway);
                ArtificialIntelligence.SelectStartingFormation(awayTeamFormation, fixture.TeamAway, fixture.TeamHome);
                awayTeamFormation.Values.Execute(p => p.Location.Invert());
            }

            var matchSimulator = new MatchSimulator(homeTeamFormation, awayTeamFormation);

            matchSimulator.Play(fixture, updateUi);
        }
예제 #14
0
        public async void PlayGame(string stringBoard)
        {
            //Thread.Sleep(4000);
            var engine    = BlackTurn(stringBoard);
            var positions = engine.GetPossiblePositions();

            if (positions == null || positions.Count == 0)
            {
                await Clients.Caller.SendAsync("End", "White won");

                return;
            }

            var ai       = new ArtificialIntelligence();
            var position = ai.GetNextMove(positions);
            var newGame  = _gameService.Get(Context.ConnectionId);

            newGame.Position = position;
            var newPositions = WhiteTurn(position[position.Count - 1]).GetPossiblePositions();

            newGame.PossiblePositions = newPositions;
            _gameService.Update(Context.ConnectionId, newGame);
            await Clients.Caller.SendAsync("Start", JsonConvert.SerializeObject(newGame));
        }
예제 #15
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="RoamBehavior"/> class.
 /// </summary>
 /// <param name="ai">The ai component this behavior belongs to.</param>
 /// <param name="random">The randomizer to use for decision making.</param>
 public RoamBehavior(ArtificialIntelligence ai, IUniformRandom random)
     : base(ai, random, 0)
 {
 }
예제 #16
0
 public AIStateCratePicked(ArtificialIntelligence brains)
     : base(brains)
 {
     _ownerBrain = (SlaveBrains)brains;
 }
 public patch_NoiseTracker(ArtificialIntelligence AI, Tracker tracker) : base(AI, tracker)
 {
 }
예제 #18
0
 public AIStateDetectSlave(ArtificialIntelligence brains) : base(brains)
 {
     _ownerBrain = (WarriorBrains)brains;
 }
예제 #19
0
 public AIStateAlert(ArtificialIntelligence brains, float searchDistance = 30f) : base(brains)
 {
     _searchDistance = searchDistance;
 }
예제 #20
0
        public void EndTurn()
        {
            if (IsGameFinished)
            {
                return;
            }

            var currentPlayerCanMove = false;

            foreach (var cell in Cells)
            {
                if (cell.Checker != null && cell.Checker.IsShotDown)
                {
                    cell.Checker = null;
                    var position = cell.GetCellPosition();
                    Cells[position.Get_row() * Width + position.Get_column()].Checker = null;
                }

                if (
                    cell.Checker == null ||
                    cell.Checker.IsWhite != CurrentWhiteTurn ||
                    (
                        cell.GetBattleCells().Count <= 0 &&
                        cell.GetAllowedPositions().Count <= 0
                    )
                    )
                {
                    continue;
                }
                currentPlayerCanMove = true;
//                break;
            }

            SaveInDeskHistory();
            var isDraw   = false;
            var drawType = 0;

            /*
             * Draw condition:
             * one desk position repeet 3 times - CheckTripplePosition
             * if at the end of the game three queans (or more) against one quean enemy, his 15th move (counting from the moment of equality of forces) will not take the opponent`s checker - Check15ThQueansBattle
             * if in a position in which both rivals have a quean, the balance of forces has not changed (i.e., there has not been a take, and no single checker has become a quean) over:
             * in 2 and 3-figure endings - 5 moves,
             * in 4 and 5-figure endings - 30 moves,
             * in 6 and 7-figure endings - 60 moves. - CheckPowerResistance
             */
            if (CheckTripplePosition() || Check15ThQueansBattle() || CheckPowerResistance())
            {
                isDraw = true;
            }


            if (!_isBotSimulation)
            {
                Console.WriteLine($@"[{(CurrentWhiteTurn ? "White" : "Black")}]Next turn!{Environment.NewLine}");
                if (_autoRotate)
                {
                    Rotation += 2;
                }
                ((MainWindow)Application.Current.MainWindow)?.UpdateRotation();
            }

            if (!isDraw && currentPlayerCanMove)
            {
                return;
            }
            if (!_isBotSimulation)
            {
                ArtificialIntelligence.IncrementSeed();
            }
            UnselectLastCell();
            if (isDraw) //check draw type
            {
                drawType = ShowDrawType();
            }

            NotifyOfDeskChanged();

            IsGameFinished = true;
            if (!_isBotSimulation)
            {
                ((MainWindow)Application.Current.MainWindow)?.EngGame(isDraw && currentPlayerCanMove ? drawType : (!CurrentWhiteTurn ? 1 : 0));
            }
        }
예제 #21
0
 public AIState(ArtificialIntelligence AI)
 {
     this.AI = AI;
 }
예제 #22
0
 private void InitAI()
 {
     me = new QuantaOrganismState("me", rand.Next(1, 40), rand.Next(1, 40));
     ai = new ArtificialIntelligence(me);
 }
 public GoToEnemySection(ArtificialIntelligence AI) : base(AI)
 {
 }
예제 #24
0
 public AIStateBase(ArtificialIntelligence brains)
 {
     _masterBrain = brains;
     _transitions = new Dictionary <EAIState, Action>();
 }
 public FoundLife(ArtificialIntelligence AI) : base(AI)
 {
 }
예제 #26
0
 private void InitAI()
 {
     me = new QuantaOrganismState("me", rand.Next(1, 40), rand.Next(1, 40));
     ai = new ArtificialIntelligence(me);
 }
 public patch_RainTracker(ArtificialIntelligence AI) : base(AI)
 {
 }
예제 #28
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="Behavior"/> class.
 /// </summary>
 /// <param name="ai">The AI component.</param>
 /// <param name="random">The randomizer to use for decision making.</param>
 /// <param name="pollRate">The poll rate in seconds.</param>
 protected Behavior(ArtificialIntelligence ai, IUniformRandom random, float pollRate)
 {
     AI        = ai;
     Random    = random;
     _pollRate = (int)(pollRate * Settings.TicksPerSecond);
 }
예제 #29
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="MoveBehavior"/> class.
 /// </summary>
 /// <param name="ai">The ai component this behavior belongs to.</param>
 /// <param name="random">The randomizer to use for decision making.</param>
 public MoveBehavior(ArtificialIntelligence ai, IUniformRandom random)
     : base(ai, random, 1)
 {
 }
예제 #30
0
 public AIStateAttack(ArtificialIntelligence brains, int leaveDistance = 60)
     : base(brains)
 {
     _leaveDistance = leaveDistance;
 }
예제 #31
0
 private void Start()
 {
     _image = GetComponent <Image>();
     _text  = GetComponentInChildren <Text>();
     _owner = transform.parent.GetComponentInParent <ArtificialIntelligence>();
 }