new void Awake() { Cursor.visible = false; runner = GetComponent <Runner>(); data = GetComponent <DataManager> (); options = GetComponent <OptionsManager> (); state = GetComponent <StateManager> (); logger = GetComponent <Logger>(); sync = GetComponent <GameSync>(); network = GetComponent <WinnitronNetwork>(); logOutput = GetComponent <LogOutputHandler>(); VersionNumber = versionNumber; GM.logger.Info("##### VERSION " + versionNumber + " #####"); writeProcessInfo(); //Not 100% sure why the jukebox is here. :S if (GameObject.Find("Jukebox")) { jukebox = GameObject.Find("Jukebox").GetComponent <Jukebox>(); } //Do Windows window management shizzle ResetScreen(); }
public void Synchronize(GameSync sync) { lock (Board) // We don't want to call this while the board is being rotated { // Clear board for (ushort y = 0; y < 11; ++y) { for (ushort x = 0; x < 8; ++x) { BoardFieldVm[x, y].Field.Card = null; } } // Update all fields _players[0].Update(sync.Player1); _players[1].Update(sync.Player2); foreach (var field in sync.FieldsWithCards) { Board[field.X, field.Y].Update(field, _players); } } // Cause access to UI controls. Must be within UI thread. Application.Current.Dispatcher.Invoke(() => { LastExecutedCommand = sync.LastExecutedCommand; Phase = sync.Phase; }); CommandManager.InvalidateRequerySuggested(); // Confirm button on deployment field does not get enabled }
// TODO: SynchronizationContext public async Task <bool> SendGameCommandAsync(string command) { bool result; if (!IsInSinglePlayerMode) { result = await _client.SendGameCommand(UID, command); } else { // Currently AI Training is only supported in Singleplayer mode. // Code may later be moved up and modified to work also in online mode. // AI Training block. if (UiGlobals.TrainAiInBackground) { // Load AI if not already done if (UiGlobals.TraineeAi == null) { // Try to get a trainable AI intance var aiPlugs = PluginHandler.Instance.GetPlugins <IArtificialIntelligenceFactory>(); var fac = aiPlugs.FirstOrDefault(o => o.Metadata.Name == UiGlobals.TraineeAiName); if (fac != null) { UiGlobals.TraineeAi = fac.CreateInstance() as ITrainableAI; if (UiGlobals.TraineeAi != null) { UiGlobals.TraineeAi.IsAiHost = true; } } } if (UiGlobals.TraineeAi == null) { UiGlobals.TrainAiInBackground = false; } else // Do the training { UiGlobals.TraineeAi.Train(GameSync.FromGame(_localGame, 0, 1), command); } } result = await _localGame.ExecuteCommand(command, 1); SyncLocalGame(); } if (result) { IsActionsMenuVisible = false; } if (!result) { _parent.ShowError?.Invoke("Error"); } return(result); }
void Awake() { if (instance != null) { Destroy(this.gameObject); } else { instance = this; } }
public void GameSyncSerialization() { var game = new Game(); game.Board[0, 0].Card = new OnlineCard() { IsFaceUp = false, Owner = game.Players[0], Type = OnlineCardType.Link }; game.Board[1, 0].Card = new OnlineCard() { IsFaceUp = false, Owner = game.Players[1], Type = OnlineCardType.Virus }; var sync = GameSync.FromGame(game, 0, 1); var str = JsonConvert.SerializeObject(sync, new JsonSerializerSettings { DefaultValueHandling = DefaultValueHandling.Ignore }); sync = JsonConvert.DeserializeObject <GameSync>(str); Assert.IsNotNull(sync); Assert.IsTrue(sync.FieldsWithCards.Exists(o => o.Card?.Type == OnlineCardType.Link)); Assert.IsFalse(sync.FieldsWithCards.Exists(o => o.Card?.Type == OnlineCardType.Virus)); }
void SyncLocalGame() { Synchronize(GameSync.FromGame(_localGame, 0, 1)); }
public void Train(GameSync sync, string command) { Synchronize(sync); if (_net1 == null) { _net1 = new NeuralNetwork(InputsNet, HiddenNet, OutputsNet1); _net1.Mutate(MutateDelta); } if (_net2 == null) { _net2 = new NeuralNetwork(InputsNet, HiddenNet, OutputsNet2); _net2.Mutate(MutateDelta); } // Deployment is random // and net cannot play any cards. if (!command.StartsWith("mv", StringComparison.InvariantCultureIgnoreCase) || command.Length < 4) { return; } command = command.Substring(3).Trim(); var split = command.Split(new[] { ',' }); if (split.Length != 4) { return; } ReplaceLettersWithNumbers(ref split); uint x1, x2, y1, y2; if (!uint.TryParse(split[0], out x1) || !uint.TryParse(split[1], out y1) || !uint.TryParse(split[2], out x2) || !uint.TryParse(split[3], out y2)) { return; } // Convert to zero based index: --x1; --x2; --y1; --y2; if (x1 > 7 || x2 > 7 || (y1 > 7 && y1 != 10) || (y2 > 7 && y2 != 10)) { return; } // We cannot train net1. It's output has no definite value that could be // calculated. We must implement a scoring model first. // Train Net 2: var field1 = Board[x1, y1]; ApplyInputs(Net2, field1); double[] expectedOutput = new double[12]; int relX = (int)x2 - (int)x1; int relY = (int)y2 - (int)y1; int i = 0; bool found = false; for (; i < 12 && !found; ++i) { if (InputArray2[i].X == relX && InputArray2[i].Y == relY) { found = true; break; } } if (!found) { return; // Bad! } expectedOutput[i] = 1; double[][] trainData = new double[1][]; trainData[0] = new double[InputsNet + OutputsNet2]; Array.Copy(Net2.Inputs, trainData[0], InputsNet); Array.Copy( expectedOutput, 0, trainData[0], InputsNet, OutputsNet2); Net2.Train(trainData, 50, 0.05, 0.01); Net2.SaveAsFile("NouAi_1.txt"); //if (!System.IO.File.Exists("NouAi_0.txt")) // Net1.SaveAsFile("NouAi_0.txt"); }
static void BackPropTraining() { var mia = new Mia(); Nou nou = (Nou) new NouFactory().CreateInstance(); mia.IsAiHost = true; nou.IsAiHost = true; var p1 = new PlayerState(1); var p2 = new PlayerState(2); var p1Sync = new PlayerState.Sync { PlayerNumber = 1 }; var p2Sync = new PlayerState.Sync { PlayerNumber = 2 }; // Generate random Board states and let Nou learn what Mia would do. var rnd = new Random(); Console.Write("Training...."); var left = Console.CursorLeft; var top = Console.CursorTop; for (int i = 0; i < 10000; ++i) { Console.SetCursorPosition(left, top); Console.Write(i + 1); var sync = new GameSync { Player1 = p1Sync, Player2 = p2Sync }; sync.Phase = GamePhase.Player1Turn; sync.FieldsWithCards = new List <BoardField.Sync>(); // Random Board // 8 Cards on each side, 4x Virus, 4x Link List <OnlineCard> cards = new List <OnlineCard>(); for (int j = 0; j < 4; ++j) { cards.Add(new OnlineCard { Owner = p1, Type = OnlineCardType.Link }); cards.Add(new OnlineCard { Owner = p2, Type = OnlineCardType.Link }); cards.Add(new OnlineCard { Owner = p1, Type = OnlineCardType.Virus }); cards.Add(new OnlineCard { Owner = p2, Type = OnlineCardType.Virus }); } var board = new List <BoardField>(); for (ushort y = 0; y < 11; ++y) { for (ushort x = 0; x < 8; ++x) { board.Add(new BoardField(x, y)); } } while (cards.Count > 0) { // 90% propability of beeing on board ( y <= 7 ) int ymax = rnd.NextDouble() <= .9 ? 7 : 9; int boardIndex = rnd.Next(board.Count); if (board[boardIndex].Y > ymax) { continue; } var field = board[boardIndex]; board.RemoveAt(boardIndex); field.Card = cards[0]; cards.RemoveAt(0); sync.FieldsWithCards.Add(field.GetSync()); } mia.Synchronize(sync); nou.Train(sync, mia.PlayTurn()); } Console.WriteLine("\nFinished. Press any key to continue"); Console.ReadKey(); }
/// <summary> /// Constructor. /// </summary> /// <param name="sync"></param> public GameSyncEventArgs(GameSync sync) { Sync = sync; }