public HistoriqueForm(ConfigurationGame conf, DateTime time, GameSimulation maSimulation)
 {
     InitializeComponent();
     this.conf = conf;
     this.time = time;
     this.maSimulation = maSimulation;
     ajoute_element();
 }
Ejemplo n.º 2
0
    private void SetupSimulation()
    {
        //deserialize key data
        m_gstSettings.Deserialize();

        //create list of all players
        List <byte> bPlayerCharacters = new List <byte>(m_playerCount);

        //fill player character list
        for (int i = 0; i < m_playerCount; i++)
        {
            bPlayerCharacters.Add(0);
        }

        m_conGameData = new ConstData(bPlayerCharacters);

        m_simGameSim = new GameSimulation(m_gstSettings, m_conGameData);
    }
Ejemplo n.º 3
0
    // Use this for initialization
    void Start()
    {
        simulation = new GameSimulation();


        server = new TCPServer(simulation);

        cam = GameObject.Find("CameraRig").GetComponent <StadiumCam>();

        scoreBoard = GameObject.Find("Scoreboard").GetComponent <Text>();
        timer      = GameObject.Find("Timer").GetComponent <Text>();

        gameDuration = new TimeSpan(0, 0, Int32.Parse(ConfigValueStore.GetValue("game_time")));

        timer.text = string.Format("{0:hh\\:mm\\:ss}", gameDuration);

        scoreRefreshTime = DateTime.Now;
    }
Ejemplo n.º 4
0
    private void RefreshScores()
    {
        var scores = simulation.GetScores();


        StringBuilder sb = new StringBuilder();

        sb.Append("LEADERBOARD");

        sb.AppendLine();
        sb.AppendLine();

        if (!ConfigValueStore.GetBoolValue("team_mode"))
        {
            foreach (TankController t in scores)
            {
                sb.Append(t.Name + " - " + t.Points);
                sb.AppendLine();
            }
        }
        else
        {
            foreach (string team in simulation.teams.Keys)
            {
                int teamTotal = 0;
                foreach (TankController t in scores)
                {
                    if (GameSimulation.GetTeamName(t.Name) == team)
                    {
                        teamTotal += t.Points;
                    }
                }
                sb.Append(team + " - " + teamTotal);
                sb.AppendLine();
            }
        }

        scoreBoard.text = sb.ToString();

        scoreRefreshTime = DateTime.Now;
    }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            GameDataParser gameDataParser = new GameDataParser();
            GameData       gameData       = gameDataParser.GetGameData(GameData.FilePathSuccess);

            foreach (string[] sequence in gameData.ActionSequences)
            {
                GameSimulation simulation = new GameSimulation();
                simulation.Init(
                    gameData.BoardSize,
                    gameData.StartingPosition,
                    gameData.TurtleRotation,
                    gameData.EndPosition,
                    gameData.MinePositions,
                    sequence.ToList()
                    );

                System.Console.WriteLine("------Simulation Started------");
                simulation.RunSimulation();
                simulation.LogResult();
            }
        }
Ejemplo n.º 6
0
        public override void OnInitialise()
        {
            //lighting
            fpsLabel.Visible = true;
            SystemCore.ActiveScene.SetUpBasicAmbientAndKey();
            SystemCore.ActiveScene.SetDiffuseLightDir(0, new Vector3(0.01f, 1, 0.01f));
            SystemCore.ActiveScene.FogEnabled = false;



            //input
            input = SystemCore.GetSubsystem <InputManager>();
            input.AddKeyDownBinding("CameraForward", Keys.Up);
            input.AddKeyDownBinding("CameraBackward", Keys.Down);
            input.AddKeyDownBinding("CameraLeft", Keys.Left);
            input.AddKeyDownBinding("CameraRight", Keys.Right);
            input.AddKeyPressBinding("MainMenu", Keys.Escape);
            var binding = input.AddKeyPressBinding("WireframeToggle", Keys.Space);

            binding.InputEventActivated += (x, y) => { SystemCore.Wireframe = !SystemCore.Wireframe; };


            //camera
            cameraObject = new GameObject();
            camComponent = new ComponentCamera();
            cameraObject.AddComponent(camComponent);
            SystemCore.GameObjectManager.AddAndInitialiseGameObject(cameraObject);
            cameraObject.Transform.SetPosition(new Vector3(0, 100, 0));
            cameraObject.Transform.Rotate(Vector3.Right, MathHelper.ToRadians(-45));
            cameraObject.Transform.Rotate(Vector3.Up, -MathHelper.PiOver4);
            SystemCore.SetActiveCamera(camComponent);


            simulation = new GameSimulation();
            simulation.InitaliseSimulation();

            base.OnInitialise();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// In this method AI makes one turn, if AI is able to make one more turn method will be called again automatically
        /// </summary>
        private void MakeTurn()
        {
            controller.ArmyFinishedMove -= MakeTurn;
            var gameSimulation = new GameSimulation(boardStorage);
            var myArmiesNumber = gameSimulation.GetNumberOfActiveArmies(playerType);

            if (myArmiesNumber == 0)
            {
                FinishTurn();
                return;
            }

            var bestMove = gameSimulation.FindBestMove(playerType);

            // if it's better not to move for all armies
            if (bestMove == null)
            {
                FinishTurn();
                return;
            }

            OnTurnEnd(bestMove);
        }
Ejemplo n.º 8
0
 private void UpdateClientWithOwnState(TcpClient client)
 {
     try
     {
         if (client.Connected)
         {
             foreach (TankController t in sim.tankControllers)
             {
                 if (t.Token == GetTokenFromEndpoint(client))
                 {
                     var obj  = GameSimulation.CreateTankState(t);
                     var json = JsonUtility.ToJson(obj);
                     SendMessage(client, MessageFactory.CreateObjectUpdateMessage(json));
                     return;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Debug.LogException(ex);
     }
 }
Ejemplo n.º 9
0
        public override void Update()
        {
            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick += DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }

            // Get distance of closest player
            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            Vector2 my_centre     = this.Position;

            if (player_centre.X < my_centre.X)
            {
                m_Facing = Facing.Left;
            }
            else
            {
                m_Facing = Facing.Right;
            }

            if (m_Facing == Facing.Left)
            {
                frameY = 0.0f;
            }
            else
            {
                frameY = 2.0f;
            }

            if (m_AnimTick >= k_MillisPerFrame)
            {
                ++frameX;

                if (frameX >= m_NumFramesX)
                {
                    frameX = 0;
                }

                m_AnimTick = 0.0f;
            }

            float dist = Vector2.Distance(my_centre, player_centre);

            // Dash Attack the player
            switch (m_AIState)
            {
            case MinionAIState.Idle:
            {
                if (m_FoundTarget == 0)
                {
                    this.Velocity = new Vector2(0.0f, 0.0f);

                    if (dist < k_MoveToPlayerDist)
                    {
                        m_FoundTarget = 1;
                        m_Direction   = Vector2.Normalize(player_centre - my_centre);
                    }
                }
                else
                {
                    this.Velocity      = m_Direction * 3.0f;
                    m_AttackWaitCount += DT;
                }

                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Charge;
                    m_FoundTarget     = 0;
                }
                break;
            }

            case MinionAIState.Charge:
            {
                if (dist < k_MinChargeDistance)
                {
                    if ((player_centre.Y > this.Position.Y) && (player_centre.Y < this.Position.Y))
                    {
                        this.Velocity.X = 10.0f * (float)m_Facing;
                        m_AIState       = MinionAIState.Dash;
                        break;
                    }
                }

                // Give up and try and get nearer
                m_AttackWaitCount += DT;
                if (m_AttackWaitCount > ATTK_COUNT)
                {
                    m_AttackWaitCount = 0.0f;
                    m_AIState         = MinionAIState.Idle;
                }

                break;
            }

            case MinionAIState.Dash:
            {
                float m_friction = 0.2f;

                // Apply friction
                if (this.Velocity.X < 0)
                {
                    this.Velocity.X += m_friction;
                }
                if (this.Velocity.X > 0)
                {
                    this.Velocity.X -= m_friction;
                }

                // Set to Zero when speed is low enough
                if (this.Velocity.X > 0 && this.Velocity.X < m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                }
                if (this.Velocity.X < 0 && this.Velocity.X > -m_friction)
                {
                    this.Velocity.X = 0;
                    m_AIState       = MinionAIState.Idle;
                    m_PickedTarget  = 0;
                }
                break;
            }
            }

            this.Position += this.Velocity;
        }
        public override void Update()
        {
            if (!Active)
            {
                return;
            }

            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick += DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }
            else
            {
                m_ChangetargetTick += DT;

                if (m_ChangetargetTick > 8.0f)
                {
                    m_PickedTarget     = 0;
                    m_ChangetargetTick = 0.0f;
                }
            }

            if (m_AnimTick >= MILLIS_PER_FRAME)
            {
                ++frameX;

                if (m_Facing == Facing.Right)
                {
                    frameY = 0.0f;
                    if (frameX >= NUM_FRAMES_X)
                    {
                        frameX = 0;
                    }
                }
                else
                {
                    frameY = 3.0f;
                    if (frameX >= NUM_FRAMES_X)
                    {
                        frameX = 0;
                    }
                }

                m_AnimTick = 0.0f;
            }

            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            Vector2 my_centre     = this.Position;

            if ((player_centre.X) < my_centre.X)
            {
                m_Facing = Facing.Left;
            }
            else
            {
                m_Facing = Facing.Right;
            }

            float       dist      = Vector2.Distance(player_centre, my_centre);
            const float speed     = 0.8f;
            Vector2     direction = Vector2.Zero;

            // Seek Player
            if (dist < 400)
            {
                direction = Vector2.Normalize(player_centre - my_centre);
                Velocity  = direction * speed;
            }
            else if (dist < 1800)
            {
                double elapsed = GameSimulation.instance.GetTotalTime();
                Velocity = new Vector2((float)Math.Cos(elapsed) * speed, (float)Math.Sin(elapsed) * speed);
            }

            // Update Pos
            Position += Velocity;
        }
Ejemplo n.º 11
0
				public void Read(BlamLib.IO.EndianReader s)
				{
					GameMode = s.ReadInt32();
					GameSimulation = (GameSimulation)s.ReadByte();
					GameNetworkType = s.ReadByte();
					GameTickRate = s.ReadInt16();
					GameInstance = s.ReadUInt64();
					Unknown010 = s.ReadInt32();
					Language = s.ReadInt32();
					DeterminismVersion = s.ReadInt32();
					MapId.Read(s);
					CachePath = s.ReadAsciiString(260);
					InitialZoneSetIndex = s.ReadInt16();
					Unknown12A = s.ReadBool();
					DumpMachineIndex = s.ReadByte();
					Unknown12C = s.ReadBool();
					Unknown12D = s.ReadBool();
					Unknown12E = s.ReadBool();
					s.Seek(1, System.IO.SeekOrigin.Current);
					GamePlayback = (GamePlayback)s.ReadInt16();
					Unknown132 = s.ReadBool();
					s.Seek(1, System.IO.SeekOrigin.Current);
					Unknown134 = s.ReadInt32();
					Unknown138 = s.ReadInt32();
					CampaignDifficulty = s.ReadInt16();
					CampaignInsertionPoint = s.ReadInt16();
					CampaignMetagameScoring = s.ReadInt16();
					Unknown142 = s.ReadBool();
					Unknown143 = s.ReadBool();
					PrimarySkulls = s.ReadInt32();
					SecondarySkulls = s.ReadInt32();
					for (int x = 0; x < Unknown14C.Length; x++) Unknown14C[x] = s.ReadBytes(30);
					Unknown1C4 = s.ReadBool();
					s.Seek(3 + 4, System.IO.SeekOrigin.Current);
					Unknown1CC = s.ReadBytes(92);
					EngineVariant.Read(s);
					s.Seek(4, System.IO.SeekOrigin.Current);
					MapVariant.Read(s);
					Game.Read(s);
				}
        private ICollection<Card> PreprocessMoves(PlayerTurnContext context, ICollection<Card> testCandidates)
        {
            var candidateMoves = new List<Card>();
            var game = new GameSimulation();

            foreach (var move in testCandidates)
            {
                bool gameIsWon = game.AmWinnerIfSimpleSimulateFullGame(new List<Card>(), move, this.Cards.ToList<Card>(), true, context, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);

                if (gameIsWon)
                {
                    candidateMoves.Add(move);
                    return candidateMoves;
                }
                else
                {
                    bool isBad = false;

                    ////foreach (var opponentsMove in opponentMoves)
                    ////{
                    ////    var tmp = game.DeepClone();

                    ////   // tmp.Move(opponentsMove);

                    ////    // did we make an assist?
                    ////    if (tmp.OppositePlayerWon())
                    ////    {
                    ////        // forget the move!
                    ////        isBad = true;
                    ////        break;
                    ////    }
                    ////}

                    if (!isBad)
                    {
                        candidateMoves.Add(move);
                    }
                }
            }

            return candidateMoves;
        }
        private float Expand(Card move, PlayerTurnContext context)
        {
            int value = 0;
            var game = new GameSimulation();

            for (int play = 0; play < NumberOfPlayouts; ++play)
            {
                bool gameIsWon = game.AmWinnerIfSimpleSimulateFullGame(new List<Card>(), move, this.Cards.ToList<Card>(), true, context, context.FirstPlayerRoundPoints, context.SecondPlayerRoundPoints);

                if (gameIsWon)
                {
                    value++;
                }
                else if (!gameIsWon)
                {
                    value--;
                }
                else if (this.rand.Next(2) == 0)
                {
                    value++;
                }
                else
                {
                    value--;
                }
            }

            return value / (float)NumberOfPlayouts;
        }
        public override void Update()
        {
            // Resolve new players
            if (m_Players.Count == 0 || m_Players.Count < Server.ServerManager.instance.NumClients())
            {
                m_Players = GameSimulation.instance.GetPlayers();
            }

            if (m_Players.Count == 0)
            {
                return;
            }

            m_AnimTick -= DT;

            if (m_PickedTarget == 0)
            {
                // Get Random target
                m_PlayerTargetIndex = GameSimulation.RandomRange(0, m_Players.Count);
                m_PickedTarget      = 1;
            }

            m_AttackWaitCount -= DT;
            Vector2 player_centre = m_Players[m_PlayerTargetIndex].Position;
            bool    break_idle    = false;
            bool    got_atatcked  = false;
            float   dist          = Vector2.Distance(Position, player_centre);

            if (dist < 300)
            {
                break_idle = true;
            }

            m_FacingTime += DT;
            if (m_FacingTime > 0.7f)
            {
                m_CanSwitchDir = true;
                m_FacingTime   = 0.0f;
            }

            if (m_AIState == ShadowAIState.Attacking || m_AIState == ShadowAIState.Idle)
            {
                if ((player_centre.X < Position.X) && m_CanSwitchDir == true)
                {
                    m_Facing       = Facing.Left;
                    m_CanSwitchDir = false;
                }
                else if ((player_centre.X > Position.X) && m_CanSwitchDir == true)
                {
                    m_Facing       = Facing.Right;
                    m_CanSwitchDir = false;
                }
            }

            Velocity = Vector2.Zero;

            // Logic
            switch (m_AIState)
            {
            case ShadowAIState.Rising:
                m_AttackWaitCount = 1.5f * ATTK_COUNT;
                break;

            case ShadowAIState.Idle:
            case ShadowAIState.Attacking:
            {
                // No object
                Velocity = new Vector2((float)m_Facing * 0.8f, 0.0f);

                // TODO *** Handle collision for walls
                break;
            }

            case ShadowAIState.Sinking:
                m_PickedTarget = 0;
                break;
            }

            Animate(break_idle, (got_atatcked && dist > 200));

            Position += Velocity;
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            GameSimulation simulation = new GameSimulation();

            simulation.Start();
        }
        public void Simulate_Starting_Result()
        {
            var subScore = new Dictionary <int, double>();
            var subCount = new Dictionary <int, int>();


            var rnd = new MT19937Generator(17);

            var score = 0.0;
            var runs  = 2000;

            var len = 0.0;

            for (var run = 0; run < runs; run++)
            {
                var state = new GameState(new Settings());
                state.OnButton = (run & 1) == 1 ? PlayerType.player1 : PlayerType.player2;

                var simulator = new GameSimulation();

                var subs = new List <int>();
                var sc   = simulator.GetScore(state, rnd, subs);
                score += sc;

                foreach (var sub in subs)
                {
                    var key0 = 20 * ((10 + sub) / 20);
                    var key1 = 4000 - key0;

                    if (!subCount.ContainsKey(key0))
                    {
                        subScore[key0] = 0;
                        subCount[key0] = 0;
                    }
                    if (!subCount.ContainsKey(key1))
                    {
                        subScore[key1] = 0;
                        subCount[key1] = 0;
                    }
                    subScore[key0] += sc;
                    subCount[key0] += 1;

                    subScore[key1] += 1.0 - sc;
                    subCount[key1] += 1;
                }

                len += subs.Count;
            }
            var act    = score / runs;
            var actLen = len / runs;

            Console.WriteLine();

            foreach (var key in subCount.Keys.OrderBy(s => s))
            {
                Console.WriteLine("{0}\t{1:0.0%}\t{2}", key, subScore[key] / subCount[key], subCount[key]);
            }

            Console.WriteLine("score: {0:0.0%}, len: {1:0.0}", act, actLen);

            var exp = 1.0;

            Assert.AreEqual(exp, act);
        }