private string TestJson(string filePath)
        {
            string json = ExtractJson(filePath);

            //Parse console input
            List <JToken> jTokenList = ParsingHelper.ParseJson(json);
            List <JToken> finalList  = new List <JToken>();

            PlayerWrapper player1 = new PlayerWrapper("human");
            PlayerWrapper player2 = new PlayerWrapper("human");

            RefereeAdapter referee = new RefereeAdapter(player1, player2);

            foreach (JToken jtoken in jTokenList)
            {
                try
                {
                    referee.JsonCommand(jtoken, finalList);
                }
                catch (RefereeException)
                {
                    break;
                }
            }

            return(JsonConvert.SerializeObject(finalList));
        }
Beispiel #2
0
        public void ClientInvalidJsonTests()
        {
            int           port    = 8280;
            List <string> configs = new List <string>()
            {
                "send json object on make a move",
                "send json array on register",
                "send json array on make a move",
            };

            foreach (string config in configs)
            {
                PlayerClientIllegal client  = new PlayerClientIllegal("localhost", port, "illegal", config);
                PlayerWrapper       player1 = new PlayerWrapper(port);
                PlayerWrapper       player2 = new PlayerWrapper("less dumb");
                List <string>       victors = Admin.AdministerGame(player1, "remote player", player2, "local player", 9);

                Assert.AreEqual(victors.Count, 1);
                if (victors.Count == 1)
                {
                    Assert.AreEqual(victors[0], "local player");
                }

                port++;
            }
        }
Beispiel #3
0
        public void PlayerIllegalMovesTests()
        {
            int           port    = 8380;
            List <string> configs = new List <string>()
            {
                "always return 1-1",
                "return 19-19 once",
                "return 99-99 once",
                "return characters once",
                "return numbers once",
                "return array once",
                "pass forever",                 //not illegal, but will let other player win
                "return empty",
            };

            foreach (string config in configs)
            {
                PlayerClientIllegal client  = new PlayerClientIllegal("localhost", port, "illegal", config);
                PlayerWrapper       player1 = new PlayerWrapper(port);
                PlayerWrapper       player2 = new PlayerWrapper("less dumb");
                List <string>       victors = Admin.AdministerGame(player1, "remote player", player2, "local player", 9);

                Assert.AreEqual(victors.Count, 1);
                if (victors.Count == 1)
                {
                    Assert.AreEqual(victors[0], "local player");
                }

                port++;
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            button = FindViewById <Button>(Resource.Id.myButton);

            button.Click += delegate { button.Text = $"{count++} clicks!"; };

            //Create the PlayerWrapper
            PlayerWrapper pv = new PlayerWrapper(null);

            //Register to events from the Wrapper Lib
            regHandler = pv.AsEventDispatcherWrapper().AddEventListener(this);
            var mv = new MediaLoadEventWrapper(null);
            //Read settings from the Original Lib
            PlayerSettings settings = pv.AsSettings();

            if (settings.Protection == DRMProtection.PlayReady)
            {
                Console.WriteLine("PlayerReady protection");
            }
        }
Beispiel #5
0
        public void ClientDisconnectTests()
        {
            int           port    = 8180;
            List <string> configs = new List <string>()
            {
                "disconnect on connect B",
                "disconnect on connect A",
                "disconnect on register",
                "disconnect on receive stones",
                "disconnect on make a move"
            };

            foreach (string config in configs)
            {
                try
                {
                    PlayerClientIllegal client = new PlayerClientIllegal("localhost", port, "illegal", config);
                }
                catch (PlayerClientException) { };
                PlayerWrapper player1 = new PlayerWrapper(port);
                PlayerWrapper player2 = new PlayerWrapper("less dumb");
                List <string> victors = Admin.AdministerGame(player1, "remote player", player2, "local player", 9);

                Assert.AreEqual(victors.Count, 1);
                if (victors.Count == 1)
                {
                    Assert.AreEqual(victors[0], "local player");
                }

                port++;
            }
        }
Beispiel #6
0
        public bool BallInlineWithGoal(PlayerWrapper car, BallWrapper ball)
        {
            var ballInlineWithGoal = false;
            var enemyGoal          = GetEnemyGoal();

            var carToGoalAngle  = Math.Atan2(enemyGoal.Y - car.Location.Y, enemyGoal.X - car.Location.X);
            var ballToGoalAngle = Math.Atan2(enemyGoal.Y - ball.Location.Y, enemyGoal.X - ball.Location.X);

            var range = 45;

            if (ballToGoalAngle <= (carToGoalAngle + range) && ballToGoalAngle >= (carToGoalAngle - range))
            {
                // Correct the angle
                if (carToGoalAngle < -Math.PI)
                {
                    carToGoalAngle += 2 * Math.PI;
                }
                else if (carToGoalAngle > Math.PI)
                {
                    carToGoalAngle -= 2 * Math.PI;
                }

                ballInlineWithGoal = true;
            }

            return(ballInlineWithGoal);
        }
Beispiel #7
0
        static void Main(string[] args)
        {
            string  go     = File.ReadAllText("go.config");
            JObject config = JsonConvert.DeserializeObject <JObject>(go);

            string ip   = config["IP"].ToObject <string>();
            int    port = config["port"].ToObject <int>();
            string path = config["default-player"].ToObject <string>();

            //Create remote player (will need explicitly create a remote player to connect to this)
            PlayerWrapper player1 = new PlayerWrapper(port);


            string  goPlayer = File.ReadAllText(path);
            JObject player   = JsonConvert.DeserializeObject <JObject>(goPlayer);

            int depth = player["depth"].ToObject <int>();

            //Create local player
            PlayerWrapper player2 = new PlayerWrapper("less dumb", depth);


            List <string> victors = Admin.AdministerGame(player1, "remote player", player2, "local player", 9);

            Console.WriteLine(JsonConvert.SerializeObject(victors.ToArray()));

            //Console.ReadLine();
        }
Beispiel #8
0
 public override void OnStart()
 {
     DropPortalToPlayer = new SocialSingleButton(0, -76.0f, "Drop portal To", new Action(() =>
     {
         APIUser ourSelectedPlayer = PlayerWrapper.GetAPIUserFromSocialPage();
         if (ourSelectedPlayer.location != null && ourSelectedPlayer.location != "")
         {
             VRCPlayer player  = PlayerWrapper.GetCurrentPlayer();
             GameObject portal = Networking.Instantiate(VRC_EventHandler.VrcBroadcastType.Always, "Portals/PortalInternalDynamic", player.transform.position + player.transform.forward * 1.5f, player.transform.rotation);
             string[] location = ourSelectedPlayer.location.Split(new char[]
             {
                 ':'
             });
             IceLogger.Log("Dropping portal to player in world ID " + location[0] + " with instance ID " + location[1]);
             Networking.RPC(RPC.Destination.AllBufferOne, portal, "ConfigurePortal", new Il2CppSystem.Object[]
             {
                 (Il2CppSystem.String)location[0],
                 (Il2CppSystem.String)location[1],
                 new Il2CppSystem.Int32
                 {
                     m_value = 0
                 }.BoxIl2CppObject()
             });
             VRCUiManager.prop_VRCUiManager_0.Method_Public_Void_Boolean_2(false);
         }
     }));
 }
Beispiel #9
0
        /* Passes the game, updating _pass_count, _current_player, and _board_history
         * throws and exception if game should end and updates _victors (sorted by lexigraphical order)
         */
        public void Pass()
        {
            _pass_count++;
            _current_player = _current_player == _player1 ? _player2 : _player1;

            //update _board_history
            _board_history.Insert(0, _board_history[0]);
            if (_board_history.Count == 4)
            {
                _board_history.RemoveAt(3);
            }

            if (_pass_count >= 2)
            {
                JObject scores = RuleCheckerWrapper.Score(_board_history[0].GetBoard());
                if (scores["B"].ToObject <int>() == scores["W"].ToObject <int>())
                {
                    _victors.Add(_player1);
                    _victors.Add(_player2);
                    _victors.Sort(CustomComparators.ComparePlayers);
                }
                else if (scores["B"].ToObject <int>() > scores["W"].ToObject <int>())
                {
                    _victors.Add(_player1);
                }
                else
                {
                    _victors.Add(_player2);
                }

                throw new RefereeException("Game has ended");
            }
        }
Beispiel #10
0
        /*
         * Simulates a move being made and updates _board_history, _pass_count, and current_player
         * If the move is illegal, throws an exception adn updates _victors
         */
        public void Play(string point)
        {
            try
            {
                RuleCheckerWrapper.Play(_current_player.GetStone(), point, GetBoardHistory());
            }
            catch (RuleCheckerException)
            {
                if (_current_player == _player1)
                {
                    _victors.Add(_player2);
                }
                else
                {
                    _victors.Add(_player1);
                }
                throw new RefereeException("Invalid Play in Referee: an illegal move has been made");
            }

            //update _board_history
            BoardWrapper b = new BoardWrapper(_board_history[0].GetBoard(), _board_history[0].GetSize());

            b.PlaceStone(_current_player.GetStone(), point);
            b.RemoveDeadStones();
            _board_history.Insert(0, b);
            if (_board_history.Count == 4)
            {
                _board_history.RemoveAt(3);
            }

            _pass_count     = 0;
            _current_player = _current_player == _player1 ? _player2 : _player1;
        }
    public static int ComparePlayers(PlayerWrapper playerA, PlayerWrapper playerB)
    {
        string a = playerA.GetName();
        string b = playerB.GetName();

        int aL = a.Length;
        int bL = b.Length;

        for (int i = 0; i < Math.Min(aL, bL); i++)
        {
            if (char.IsUpper(a[i]) && char.IsLower(b[i])) //A < b
            {
                return(-1);
            }
            else if (char.IsLower(a[i]) && char.IsUpper(b[i])) //a > B
            {
                return(1);
            }
            else //if characters are the same case or one character isn't a letter
            {
                return(a[i].CompareTo(b[i]));
            }
        }

        return((aL > bL) ? 1 : -1);
    }
Beispiel #12
0
 public Referee(int size = 19)
 {
     _board_history = new List <BoardWrapper>();
     _victors       = new List <PlayerWrapper>();
     _board_history.Add(new BoardWrapper(null, size));
     _current_player = _player1;
 }
Beispiel #13
0
        public override void OnUpdate()
        {
            if (Input.GetKeyDown(KeyCode.U))
            {
                PlayerWrapper.UpdateFriendList();

                var allPlayers = PlayerWrapper.GetAllPlayers().ToArray();
                for (int i = 0; i < allPlayers.Length; i++)
                {
                    Transform sRegion = allPlayers[i].transform.Find("SelectRegion");
                    allPlayers[i].field_Internal_VRCPlayer_0.friendSprite.color         = Color.green;
                    allPlayers[i].field_Internal_VRCPlayer_0.speakingSprite.color       = Color.white;
                    allPlayers[i].field_Internal_VRCPlayer_0.namePlate.mainText.color   = Color.white;
                    allPlayers[i].field_Internal_VRCPlayer_0.namePlate.dropShadow.color = Color.black;
                    allPlayers[i].field_Internal_VRCPlayer_0.namePlateTalkSprite        = allPlayers[i].field_Internal_VRCPlayer_0.namePlateSilentSprite;

                    if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "Veteran user")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.red);
                    }
                    else if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "Trusted user")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.magenta);
                    }
                    else if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "Known user")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.Lerp(Color.yellow, Color.red, 0.5f));
                    }
                    else if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "User")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.green);
                    }
                    else if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "New user")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(new Color(0.3f, 0.72f, 1f));
                    }
                    else if (PlayerWrapper.GetTrustLevel(allPlayers[i]) == "Visitor")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.gray);
                    }

                    if (sRegion != null)
                    {
                        sRegion.GetComponent <Renderer>().sharedMaterial.SetColor("_Color", Color.red);
                    }

                    HighlightsFX.prop_HighlightsFX_0.field_Protected_Material_0.SetColor("_HighlightColor", Color.red);

                    if (allPlayers[i].field_Internal_VRCPlayer_0.prop_String_1 == "usr_77979962-76e0-4b27-8ab7-ffa0cda9e223")
                    {
                        allPlayers[i].field_Private_VRCPlayerApi_0.SetNamePlateColor(Color.black);
                        allPlayers[i].field_Internal_VRCPlayer_0.namePlate.mainText.color   = Color.red;
                        allPlayers[i].field_Internal_VRCPlayer_0.namePlate.dropShadow.color = Color.clear;
                        allPlayers[i].field_Internal_VRCPlayer_0.friendSprite.color         = Color.red;
                        allPlayers[i].field_Internal_VRCPlayer_0.speakingSprite.color       = Color.red;
                    }
                }
            }
        }
 public static void TeleportToTile(this PlayerWrapper player, int x, int y)
 {
     UnityClient.Map.EntityPositions.RemoveEntity(player, player.Position);
     player.PlayerObject.transform.position = new Vector2(x * 16, -y * 16);
     UnityClient.Player.Position.X          = x;
     UnityClient.Player.Position.Y          = y;
     UnityClient.Map.EntityPositions.AddEntity(player, player.Position);
 }
Beispiel #15
0
 public PlayerData(PlayerWrapper p, string n)
 {
     PlayerObject = p;
     Name         = n;
     Score        = 0;
     HasCheated   = false;
     wonAgainst   = new List <PlayerData>();
 }
Beispiel #16
0
        public override bool CanBeHitByNPC(NPC npc, ref int cooldownSlot)
        {
            NPCWrapper    npcWrapper    = new NPCWrapper(npc);
            PlayerWrapper playerWrapper = new PlayerWrapper(player);

            Calc.OnHit(npcWrapper, playerWrapper);
            return(Calc.CanBeHitBy(npcWrapper, playerWrapper, base.CanBeHitByNPC(npc, ref cooldownSlot), false));
        }
Beispiel #17
0
 // Use this for initialization
 void Start()
 {
     if (jsonData != null)
     {
         playerWrapper = JsonUtility.FromJson <PlayerWrapper> (jsonData.text);
         Debug.LogFormat("{0}", playerWrapper.players [0].x0);
     }
 }
Beispiel #18
0
        public override bool CanBeHitByProjectile(Projectile proj)
        {
            ProjectileWrapper projWrapper   = new ProjectileWrapper(proj);
            PlayerWrapper     playerWrapper = new PlayerWrapper(player);

            Calc.OnHit(projWrapper, playerWrapper);
            return(Calc.CanBeHitBy(projWrapper, playerWrapper, base.CanBeHitByProjectile(proj), false));
        }
Beispiel #19
0
        public override void ModifyHitByNPC(NPC npc, ref int damage, ref bool crit)
        {
            float         f             = default;
            NPCWrapper    npcWrapper    = new NPCWrapper(npc);
            PlayerWrapper playerWrapper = new PlayerWrapper(player);

            Calc.OnHit(npcWrapper, playerWrapper);
            Calc.ModifyHitBy(npcWrapper, playerWrapper, ref damage, ref f, ref crit);
        }
 public RefereeWrapper(PlayerWrapper player1, PlayerWrapper player2, int size = 19)
 {
     if (size < 1 || size > 19)
     {
         throw new WrapperException("Invalid size passed to RefereeWrapper");
     }
     _referee     = new Referee(player1, player2, size);
     _players_set = 0;
 }
        public override bool PreAI(Projectile projectile)
        {
            ProjectileWrapper projWrapper = new ProjectileWrapper(projectile);

            if (projWrapper.GetTeam() == Team.PlayerFriendly || projWrapper.GetTeam() == Team.Unknown)
            {
                ClosestTarget closest = ClosestTarget.Null;
                for (int i = 0; i < Main.maxNPCs; i++)
                {
                    NPC npc = Main.npc[i];
                    if (npc != null && npc.active)
                    {
                        NPCWrapper npcWrapper = new NPCWrapper(npc);
                        if (npc.GetGlobalNPC <NPCTyping>().GetAbility().AttractProjectile(
                                new AbilityLookup.AttractProjectileParameters(projWrapper, npcWrapper)))
                        {
                            ClosestTarget newClosest = new ClosestTarget(npc, projectile);
                            if (newClosest.distance < closest.distance)
                            {
                                closest = newClosest;
                            }
                        }
                    }
                }
                if (closest.id >= 0)
                {
                    ProjectileHome(projectile, closest, Main.npc[closest.id].Center);
                }
            }
            else if (projWrapper.GetTeam() == Team.EnemyNPC)
            {
                ClosestTarget closest = ClosestTarget.Null;
                for (int i = 0; i < Main.maxPlayers; i++)
                {
                    Player player = Main.player[i];
                    if (player != null && player.active)
                    {
                        PlayerWrapper playerWrapper = new PlayerWrapper(player);
                        if (playerWrapper.GetModPlayer <PlayerTyping>().GetAbility().AttractProjectile(
                                new AbilityLookup.AttractProjectileParameters(projWrapper, playerWrapper)))
                        {
                            ClosestTarget newClosest = new ClosestTarget(player, projectile);
                            if (newClosest.distance < closest.distance)
                            {
                                closest = newClosest;
                            }
                        }
                    }
                }
                if (closest.id >= 0)
                {
                    ProjectileHome(projectile, closest, Main.player[closest.id].Center);
                }
            }

            return(base.PreAI(projectile));
        }
Beispiel #22
0
        private static PlayerData CreateDefaultPlayerData(string aiType, int depth, string name)
        {
            PlayerWrapper player      = new PlayerWrapper(aiType, depth);
            string        player_name = player.Register(name);

            Console.WriteLine("Sucessfully registered default player: " + player_name);

            return(new PlayerData(player, player_name));
        }
Beispiel #23
0
        public static void TeleportToTile(this PlayerWrapper player, int x, int y)
        {
            var newPosition = new Position(x, y);

            UnityClient.Map.UpdateEntityPosition(player, player.Position, newPosition);
            UnityClient.Player.Position = newPosition;

            player.PlayerObject.transform.position = player.Position.ToUnityPosition();
        }
Beispiel #24
0
 public Referee(PlayerWrapper player1, PlayerWrapper player2, int size)
 {
     _board_history = new List <BoardWrapper>();
     _victors       = new List <PlayerWrapper>();
     _board_history.Add(new BoardWrapper(null, size));
     _player1 = player1;
     _player2 = player2;
     _size    = size;
 }
Beispiel #25
0
    // LoadPlayer
    public static PlayerWrapper LoadPlayer()
    {
        TextAsset playerJson = Resources.Load <TextAsset>(Constants.PlayerPath);

        Debug.Log("Player json: " + playerJson);
        PlayerWrapper playerWrapper = JsonUtility.FromJson <PlayerWrapper>(playerJson.text);

        return(playerWrapper);
    }
Beispiel #26
0
        public override void ModifyHitByProjectile(Projectile proj, ref int damage, ref bool crit)
        {
            float             f             = default;
            ProjectileWrapper projWrapper   = new ProjectileWrapper(proj);
            PlayerWrapper     playerWrapper = new PlayerWrapper(player);

            Calc.OnHit(projWrapper, playerWrapper);
            Calc.ModifyHitBy(projWrapper, playerWrapper, ref damage, ref f, ref crit);
        }
        public static bool FindPathTo(this PlayerWrapper player, Position position)
        {
            var path = UnityClient.Map.FindPath(player.Position, position);

            if (path != null)
            {
                player.FollowingPath = path;
            }
            return(path != null);
        }
Beispiel #28
0
    public void SaveData()
    {
        PlayerWrapper wrapper = new PlayerWrapper();

        wrapper.playerData = playerData;

        string contents = JsonUtility.ToJson(wrapper, true);

        System.IO.File.WriteAllText(path, contents);
    }
Beispiel #29
0
 public WrapBot(string botName, int botTeam, int botIndex) : base(botName, botTeam, botIndex)
 {
     State        = BotState.Kickoff;
     Action       = BotAction.Default;
     Controller   = new Controller();
     Field        = new FieldService(botTeam);
     Ball         = new BallWrapper();
     Info         = new PlayerWrapper();
     Game         = new GameWrapper();
     DesiredState = null;
 }
 public static void Send(char command, PlayerManagement.Player aPlayer)
 {
     GetInstance();
     if (instance.connected)
     {
         PlayerWrapper wrappedPlayer = new PlayerWrapper(command, aPlayer);
         string        json          = new JavaScriptSerializer().Serialize(wrappedPlayer);
         Byte[]        sendBytes     = Encoding.ASCII.GetBytes(json);
         instance.client.Send(sendBytes, sendBytes.Length);
     }
 }