static void Main(String[] args) { Interpreter = new ConsoleInterpreter(); State = new BoardState(); Random randomGenerator = null; while (true) { // Read information from standard input var consoleText = Console.ReadLine(); State.MyPlayerNumber = Interpreter.GetPlayerNumber(consoleText); MyPlayerNumber = State.MyPlayerNumber; State.UpdateBoard(Interpreter.InterpretConsole(consoleText)); if (randomGenerator == null) { DateTime startDate = new DateTime(2014, 2, 28, 7, 0, 0); randomGenerator = new Random((int)startDate.Subtract(DateTime.Now).TotalSeconds); } // Compute logic here var bestValue = -1000; var availableTrips = new List <Trip>(); for (var i = 1; i <= 4; ++i) { var trip = ComputeTrip(new Direction(i), State.Players[MyPlayerNumber].Location); if (trip.Successful) { availableTrips.Add(trip); Console.Error.WriteLine(trip.Value); if (trip.Value > bestValue) { bestValue = trip.Value; } } } //Console.Error.WriteLine("Available Directions: " + availableDirections.Count); //Console.Error.WriteLine("Available Locations: " + State.AvailableLocations.Count); if (availableTrips.Count > 0) { //Console.Error.WriteLine("Available: " + availableTrips.Count); var idealTrips = availableTrips.Where(t => t.Value == bestValue).ToList(); //Console.Error.WriteLine("Ideal: " + idealTrips.Count); var selectedTrip = idealTrips[randomGenerator.Next(0, idealTrips.Count - 1)]; // Console.Error.WriteLine("Debug messages..."); //Console.Error.WriteLine("Players: " + state.Players.Count.ToString()); //Console.Error.WriteLine("X: " + selectedTrip.OriginalLocation.X); //Console.Error.WriteLine("Y: " + selectedTrip.OriginalLocation.Y); //Console.Error.WriteLine("New X: " + selectedTrip.NewLocation.X); //Console.Error.WriteLine("New Y: " + selectedTrip.NewLocation.Y); // Write action to standard output Go(selectedTrip.Direction.Current); } else { Console.WriteLine("LEFT"); } } }
private void DrawLevelChange(int numLevel, int count, int x, int y, string levelName) { if (GameGUI.Inst.ButtonWithSound(new Rect(x, Screen.height - height - ((height + spaceHeight) * (count + numLevel)), width, height), levelName)) { GameManager.Inst.LoadLevel(ConsoleInterpreter.GetLevel(levelName)); } }
public void setupInterpreter(ConsoleInterpreter interpreter) { this.interpreter = interpreter; clearBuffer(); clearHistory(); this.interpreter.showWelcome(this, ""); }
void DoAuthenticatedLogin() { string json = loginArgs; Debug.Log("login form fields: " + json); JSONObject jsonObject = JSONObject.Parse(json); string sessionToken = jsonObject.GetString("sessionToken"); string refreshRes = CommunicationManager.Inst.RefreshCurrentUserProfile(json); if (refreshRes == sessionToken) { string displayname = jsonObject.GetString("displayname"); if (displayname == "") { displayname = jsonObject.GetString("username"); } string username = displayname; Debug.Log(username + "logged in! sessionToken: " + sessionToken); string level = jsonObject.GetString("level"); if (level == null) { level = ""; } string teamID = jsonObject.GetString("teamid"); if (teamID == null || teamID == "") { teamID = "8"; //setting up a default teamid/room for ppl to join } #if DEBUG_LOGIN teamID = jsonObject.GetString("team"); #endif // If user has a server config specified use that, otherwise it will use the default. CommunicationManager.Instance.SetServerConfig(CommunicationManager.CurrentUserProfile.ServerConfig); // if fallback room has never been set, set to default level, useful for landing people in avatar selection room by default. if (string.IsNullOrEmpty(CommunicationManager.CurrentUserProfile.Room)) { CommunicationManager.CurrentUserProfile.UpdateProfile("room", ((int)ConsoleInterpreter.GetLevel(CommunicationManager.defaultLevel)).ToString()); } GameManager.Inst.lastLevel = ConsoleInterpreter.GetLevel(CommunicationManager.defaultLevel); CommunicationManager.Instance.ConnectToSmartFox(username, teamID, level); CommunicationManager.CurrentUserProfile.IncrementLoginCount(); PlayerPrefs.SetString("vuser", CommunicationManager.CurrentUserProfile.Username); } }
public LHGConsole(LunchHourGames lhg, SpriteFont font) : base(lhg) { this.lhg = lhg; device = lhg.GraphicsDevice; spriteBatch = new SpriteBatch(device); this.font = font; background = new Texture2D(device, 1, 1, false, SurfaceFormat.Color); background.SetData <Color>(new Color[1] { new Color(0, 0, 0, 125) }); isConsoleDark = false; InputBuffer = ""; history = new ConsoleHistory(); consoleXSize = Game.Window.ClientBounds.Right - Game.Window.ClientBounds.Left - 20; consoleYSize = font.LineSpacing * LinesDisplayed + 20; lineWidth = (int)(consoleXSize / font.MeasureString("a").X) - 2; //calculate number of letters that fit on a line, using "a" as example character State = ConsoleState.Closed; StateStartTime = 0; LastKeyState = this.CurrentKeyState = Keyboard.GetState(); firstInterval = 500f; repeatInterval = 50f; //used for repeating keystrokes keyTimes = new Dictionary <Keys, double>(); for (int i = 0; i < Enum.GetValues(typeof(Keys)).Length; i++) { Keys key = (Keys)Enum.GetValues(typeof(Keys)).GetValue(i); keyTimes[key] = 0f; } this.defaultInterpreter = new DefaultInterpreter(); }
public void ConnectToSmartFox(string n, string r, string l = "") { if (smartFox != null && (smartFox.IsConnecting || smartFox.IsConnected)) { return; } #if UNITY_WEBPLAYER Debug.LogError("WebPlayer setup: " + serverName + ":" + serverPort); if (!Security.PrefetchSocketPolicy(serverName, serverPort, 500)) { Debug.LogError("Security Exception. Policy file load failed!"); } #endif username = n; roomNumToLoad = int.Parse(r); LevelToLoad = ConsoleInterpreter.GetLevel((l != "") ? l : defaultLevel); //string[] cmdLnArgs = System.Environment.GetCommandLineArgs(); //BotManager.Inst.SetBotOptions(cmdLnArgs); // Register SFS callbacks smartFox.AddEventListener(SFSEvent.CONNECTION, OnConnection); smartFox.AddEventListener(SFSEvent.CONNECTION_LOST, OnConnectionLost); smartFox.AddEventListener(SFSEvent.CONNECTION_RETRY, OnConnectionRetry); smartFox.AddEventListener(SFSEvent.CONNECTION_ATTEMPT_HTTP, OnConnectionAttemptHttp); smartFox.AddEventListener(SFSEvent.LOGIN, OnLogin); smartFox.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError); smartFox.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin); smartFox.AddEventListener(SFSEvent.ROOM_JOIN_ERROR, OnRoomJoinError); smartFox.AddEventListener(SFSEvent.ROOM_CREATION_ERROR, OnRoomCreationError); smartFox.AddEventListener(SFSEvent.EXTENSION_RESPONSE, OnExtensionResponse); // Data messages AddEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, DataMessageManager.Inst.OnRoomVariablesUpdate); AddEventListener(SFSEvent.PUBLIC_MESSAGE, DataMessageManager.Inst.OnPublicMessage); AddEventListener(SFSEvent.PRIVATE_MESSAGE, DataMessageManager.Inst.OnPrivateMessage); AddEventListener(SFSEvent.OBJECT_MESSAGE, DataMessageManager.Inst.OnObjectMessage); AddEventListener(SFSEvent.ADMIN_MESSAGE, DataMessageManager.Inst.OnAdminMessage); AddEventListener(SFSEvent.USER_VARIABLES_UPDATE, DataMessageManager.Inst.OnUserVariableUpdate); AddEventListener(SFSEvent.USER_ENTER_ROOM, DataMessageManager.Inst.OnUserEnterRoom); AddEventListener(SFSEvent.USER_EXIT_ROOM, DataMessageManager.Inst.OnUserExitRoom); // Callbacks for buddy events smartFox.AddEventListener(SFSBuddyEvent.BUDDY_LIST_INIT, OnBuddyListInit); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ERROR, OnBuddyError); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ONLINE_STATE_UPDATE, OnBuddyListUpdate); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyListUpdate); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_ADD, OnBuddyAdded); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_REMOVE, OnBuddyRemoved); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_BLOCK, OnBuddyBlocked); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_MESSAGE, OnBuddyMessage); smartFox.AddEventListener(SFSBuddyEvent.BUDDY_VARIABLES_UPDATE, OnBuddyVarsUpdate); Debug.LogError("Connecting to " + serverName + ":" + serverPort); smartFox.AddLogListener(logLevel, OnDebugMessage); smartFox.Connect(serverName, serverPort); serverConnectionStatusMessage = "Establishing Connection"; DontDestroyOnLoad(this); // keep persistent when loading new levels }
private void HandleCommandLineArgs() { bool useMonitor = false; int teamid = 0; string level = "bizsim"; string username = "******"; string password = "******"; LinkedList <string> cmds = new LinkedList <string>(); #if !UNITY_WEBPLAYER string[] cmdLnArgs = System.Environment.GetCommandLineArgs(); for (int i = 0; i < cmdLnArgs.Length; i++) { switch (cmdLnArgs[i]) { case "-batchmode": useMonitor = true; break; case "-room": case "-level": case "-roomselect": level = cmdLnArgs[++i]; break; case "-instance": case "-teamid": case "-team": teamid = Convert.ToInt32(cmdLnArgs[++i]); break; case "-cmd": cmds.AddLast(cmdLnArgs[++i]); break; default: // hacky, but assume this is extra pieces of the last command. if (cmds.Count > 0) { string newLast = cmds.Last.Value + " " + cmdLnArgs[i]; cmds.RemoveLast(); cmds.AddLast(newLast); } break; } } #endif if (useMonitor) { // These are here so the file name pulls the correct data LevelToLoad = ConsoleInterpreter.GetLevel((level != "") ? level : defaultLevel); roomNumToLoad = teamid; RecordingPlayer.Inst.Init("", true, false); mCurrentUserProfile.Login(username, password); loadUnityLevelOnRoomJoin = false; // no need for the monitor to actually load the unity scene, just needs to save the messages. ConnectToSmartFox(username, teamid.ToString(), level); while (cmds.Count > 0) { ConsoleInterpreter.Inst.ProcCommand(cmds.First.Value); cmds.RemoveFirst(); } } else if (GameManager.Inst.ServerConfig == "Assembly" || GameManager.Inst.ServerConfig == "MDONS") { try { mCurrentUserProfile.Login("assemblyGuest", "assembly[123]"); } catch (Exception e) { Debug.LogError("Profile login failed: " + e.ToString()); } Invoke("GuestConnectToSmartFox", 0.1f); } }
public void SetBotOptions(string[] cmdLnArgs) { for (int i = 0; i < cmdLnArgs.Length; i++) { switch (cmdLnArgs[i]) { case "-batchmode": botControlled = true; CommunicationManager.Inst.roomNumToLoad = 1; break; case "-chatbot": botChat = true; break; case "-stillbot": botStill = true; break; case "-roomselect": if (cmdLnArgs.Length > i + 1) { string tempRoomNum = cmdLnArgs[i + 1]; CommunicationManager.Inst.roomNumToLoad = Convert.ToInt32(tempRoomNum); } botRoomSelect = true; break; case "-levelselect": botLevelSelect = true; if (cmdLnArgs.Length > i + 1) { string levelName = cmdLnArgs[i + 1].ToString().ToLower(); CommunicationManager.LevelToLoad = ConsoleInterpreter.GetLevel(cmdLnArgs[i + 1]); } else { CommunicationManager.LevelToLoad = GameManager.Level.CAMPUS; } break; case "-delaymove": botDelayMove = true; if (cmdLnArgs.Length > i + 1) { string tempDelay = cmdLnArgs[i + 1]; botDelay = Convert.ToInt32(tempDelay); } break; case "-framerate": if (cmdLnArgs.Length > i + 1) { string tempFrameRate = cmdLnArgs[i + 1]; Application.targetFrameRate = Convert.ToInt32(tempFrameRate); } break; case "-voice": if (cmdLnArgs.Length > i + 1) { string voiceDelayStr = cmdLnArgs[i + 1]; botVoiceDelay = (float)Convert.ToDouble(voiceDelayStr); } break; default: break; } if (botControlled && !botLevelSelect) { CommunicationManager.LevelToLoad = GameManager.Level.CAMPUS; } } }