public static GameSolution Solve(Matrix gameMatrix) { var solution = new GameSolution(); var gameMatrixInv = gameMatrix.Inverse(); var unitRow = Matrix.UnitRow(gameMatrix.Rows); var unitColumn = Matrix.UnitColumn(gameMatrix.Columns); double gamePrice = 1 / (unitRow * gameMatrixInv * unitColumn)[0, 0]; var firstStrategy = gamePrice * (unitRow * gameMatrixInv); var secondStrategy = gamePrice * gameMatrixInv * unitColumn; solution.FirstPlayerStrategy = firstStrategy.Row(0); solution.SecondPlayerStrategy = secondStrategy.Column(0); return(solution); }
void OpenGameSumation(GameSolution gameSolution, int extraPoints, int extraCoins) { Text[] texts = new Text[4]; Text firstText = new Text(); UpdateData(extraPoints, extraCoins); if (gameSolution == GameSolution.WIN) { firstText.Color = Color.Green; firstText.DisplayedString = "YOU WIN"; } else { firstText.Color = Color.Red; firstText.DisplayedString = "GAME OVER"; } firstText.Font = DataLoader.font1; firstText.CharacterSize = 70; firstText.Position = new Vector2f(GameProperties.GetWinX / 6, GameProperties.GetWinY / 15); for (int i = 0; i < 4; i++) { texts[i] = new Text(); } texts[0].DisplayedString = "Extra points: " + extraPoints; texts[1].DisplayedString = "Total points: " + data.points; texts[2].DisplayedString = "Extra coins: " + extraCoins; texts[3].DisplayedString = "Total coins: " + data.coins; for (int i = 0; i < 4; i++) { texts[i].Color = Color.White; texts[i].CharacterSize = 40; texts[i].Font = DataLoader.font1; texts[i].Position = new Vector2f(GameProperties.GetWinX / 6, 3 * GameProperties.GetWinY / 15 + 80 * (i + 1)); } while (window.IsOpen && controllerLoop) { window.Clear(); window.Draw(firstText); foreach (Text text in texts) { window.Draw(text); } window.DispatchEvents(); window.Display(); } }
public void SimpleGameCanBeSolved() { char[] gameField = new char[] { 'w', 'o', 'r', 'i', 'f', 'k', 'e', 'l', 'd' }; GameInformation gameInfo = new GameInformation(gameField, 3, 3); ConcurrentWordStateMachine concurrentWordStateMachine = new ConcurrentWordStateMachine(); concurrentWordStateMachine.AddWords("./Words/English.txt"); GameSolver gameSolver = new GameSolver(concurrentWordStateMachine); GameSolution solution = gameSolver.SolveGameAsync(gameInfo).Result; Assert.True(solution.IsSolved); GameWord[] gameWords = new GameWord[] { //work new GameWord(gameInfo, new GamePoint[] { new GamePoint(gameInfo, 0, 0), new GamePoint(gameInfo, 1, 0), new GamePoint(gameInfo, 2, 0), new GamePoint(gameInfo, 2, 1) }), //field new GameWord(gameInfo, new GamePoint[] { new GamePoint(gameInfo, 1, 1), new GamePoint(gameInfo, 0, 1), new GamePoint(gameInfo, 0, 2), new GamePoint(gameInfo, 1, 2), new GamePoint(gameInfo, 2, 2) }) }; GameState expectedGameState = new GameState(gameInfo, gameWords); Assert.Contains(expectedGameState, solution.GameStates); Assert.Single(solution.GameStates); }