private static void DefineEligibilityTraces(GameBoardState st) { for (int i = 0; i < EligibilityTraces.Length; i++) { EligibilityTraces[i] = lambda * EligibilityTraces[i] + DerivativeFunction(F[i], st); } }
private void LoadNewData(GameBoardState gameBoardState) { foreach (var planet in gameBoardState.Planets) { var planetE = _game.CreateEntity(); planetE.ReplaceComponent(GameComponentsLookup.Planet, planet.Planet); planetE.ReplaceComponent(GameComponentsLookup.Position, planet.Position); planetE.ReplaceComponent(GameComponentsLookup.Mass, planet.Mass); planetE.ReplaceComponent(GameComponentsLookup.Health, planet.Health); planetE.ReplaceComponent(GameComponentsLookup.Cannon, planet.Cannon); planetE.ReplaceComponent(GameComponentsLookup.CooldownTimer, planet.CooldownTimer); } foreach (var rocket in gameBoardState.Rockets) { var rocketE = _game.CreateEntity(); rocketE.ReplaceComponent(GameComponentsLookup.FirePower, rocket.FirePower); rocketE.ReplaceComponent(GameComponentsLookup.Health, rocket.Health); rocketE.ReplaceComponent(GameComponentsLookup.Position, rocket.Position); rocketE.ReplaceComponent(GameComponentsLookup.Velocity, rocket.Velocity); rocketE.isRocket = true; } foreach (var player in gameBoardState.Players) { var playerE = _game.CreateEntity(); playerE.ReplaceComponent(GameComponentsLookup.Player, player.Player); } }
private bool TryWinningBackwardDiagonal(GameBoardMark[,] gameBoard, out GameBoardState gameBoardState) { int rowLength = gameBoard.GetLength(0); int columnLength = gameBoard.GetLength(1); var winningBackwardDiagonal = true; int rowIndex = 0, columnIndex = 0; GameBoardMark matchingMark = gameBoard[rowIndex, columnIndex]; for (; rowIndex < rowLength && columnIndex < columnLength; rowIndex++, columnIndex++) { if (gameBoard[rowIndex, columnIndex] != matchingMark) { winningBackwardDiagonal = false; break; } } if (matchingMark == GameBoardMark.Empty) { gameBoardState = GameBoardState.Active; return(false); } gameBoardState = winningBackwardDiagonal && matchingMark == GameBoardMark.X ? GameBoardState.XWinner : GameBoardState.OWinner; return(winningBackwardDiagonal); }
private static void ParameterUpdate(GameBoardState st, GameBoardState st1) { for (int i = 0; i < theta.Length; i++) { theta[i] = theta[i] + alpha * DifferenceFunction(st, st1) * EligibilityTraces[i]; } }
private string GetEmptyBoard() { var state = new GameBoardState(); var width = GameOption !.BoardWidth; var height = GameOption.BoardHeight; state.Board = new ECellState[width][]; for (var i = 0; i < state.Board.Length; i++) { state.Board[i] = new ECellState[height]; } for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { state.Board[x][y] = ECellState.Empty; } } var jsonOptions = new JsonSerializerOptions { WriteIndented = true }; return(JsonSerializer.Serialize(state, jsonOptions)); }
private Bug[,] bugInCell; // Bugs matrix that contains all the bugs on the game board. // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ /// <summary> /// Constructor of game board entity. /// </summary> /// <param name="_xPosition">Position on the X axis.</param> /// <param name="_yPosition">Position on the Y axis.</param> /// <param name="_rows">Number of rows in the game board.</param> /// <param name="_columns">Number of columns in the game board.</param> /// <param name="_speedAnimation">Speed in milliseconds with which the changes in the game board will be shown.</param> // GameBoard Constructor ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ public GameBoard(int _xPosition = 1, int _yPosition = 1, int _rows = 5, int _columns = 5, int _speedAnimation = 250) { xPosition = _xPosition; yPosition = _yPosition; if (_rows > 5) { rowsNumber = _rows; } else { rowsNumber = 5; } if (_columns > 5) { columnsNumber = _columns; } else { columnsNumber = 5; } animationSpeed = _speedAnimation; currentState = GameBoardState.PLAYING; bugInCell = new Bug[rowsNumber, columnsNumber]; InitializeGameBoard(); }
private void ReplaceTurn(GameBoardState tempBoard, string newTurn) { if (tempBoard.IsDouble) { if (tempBoard._countMovments == 4) { tempBoard.CurrentPlayer = newTurn; tempBoard._countMovments = 0; tempBoard.TurnChangaed = true; } else { tempBoard.TurnChangaed = false; } return; } if (tempBoard.Dice.Die1 == -1 && tempBoard.Dice.Die2 == -1) { tempBoard.CurrentPlayer = newTurn; tempBoard.TurnChangaed = true; } else { tempBoard.TurnChangaed = false; } }
int EvaluateHeuristic(GameBoardState boardState, PlayerTurn maxTurn) { if (boardState.Winner != null) { return(boardState.Winner == maxTurn ? int.MaxValue : int.MinValue); } int score = 0; foreach (Point[] winningComb in WinningCombinations) { foreach (Point position in winningComb) { PlayerTurn?piece = boardState.Board[position.Y, position.X]; if (piece == maxTurn) { score++; } else if (piece == GameLogicUtils.Next(maxTurn)) { score--; } } } return(score); }
public GameBoardState Clone() { GameBoardState newGbs = new GameBoardState(this.levels, this.rows, this.cols); IGameBoardState igbs = this; for (int lvl = 0; lvl < (igbs.GetNumLevels()); lvl++) { for (int row = 0; row < (igbs.GetNumRows()); row++) { for (int col = 0; col < (igbs.GetNumCols()); col++) { ISpaceState iss = igbs.GetSpaceState(lvl, row, col); newGbs.spaces[lvl][row][col].occupied = iss.IsOccupied(); IPieceState ips = iss.Occupier(); if (ips != null) { PieceState ps = ips.CreatePieceState(); newGbs.spaces[lvl][row][col].occupier = ps; newGbs.AlivePieces.Add(ps); ps.space = newGbs.spaces[lvl][row][col]; } } } } foreach (IPieceState piece in DeadPieces) { newGbs.DeadPieces.Add(piece.CreatePieceState()); } return(newGbs); }
protected void Start() { shouldUpdate = true; Debug.Assert(gemSprites.Count == (int)GemType.Gem_Count, "gem sprite count is not equal to gem type count."); var gemRow = GameConfig.Instance.gemRow; var gemColumn = GameConfig.Instance.gemColumn; _currentGemControllerMatrix = new GemController[gemRow, gemColumn]; for (int row = 0; row < gemRow; row++) { for (int column = 0; column < gemColumn; column++) { SpawnGem(row, column, true); } } _currentGameBoardState = GameBoardState.Idle; _firstSelectedGemControler = null; _secondSelectedGemControler = null; // implementations SetupStateHandlers(); }
private bool CorrectStep(GameBoardState tempBoard, int steps) { if (tempBoard.IsDouble) { if (tempBoard.Dice.Die1 == steps) { tempBoard._countMovments++; return(true); } else { return(false); }//? } if (tempBoard.Dice.Die1 == steps) { tempBoard.Dice.Die1 = -1; return(true); } if (tempBoard.Dice.Die2 == steps) { tempBoard.Dice.Die2 = -1; return(true); } return(false); }
internal void InitializeBoard(string senderName, string reciverName) { string guid = senderName; GameBoardState gameBoard = new GameBoardState(senderName, reciverName); _boards.Add(guid, gameBoard); }
public void MakeMove_WhenWinningGameMove_SetsWinner(GameBoardState gameBoardState, GameState expected) { gameBoardAnalyzerMock.AnalyzeGameBoard(board).Returns(gameBoardState); InvokeMakeMove(); Assert.That(systemUnderTest.GameState, Is.EqualTo(expected)); }
public static bool GameOver(GameBoardState s) { if (s.getCheckersOnTarget(White) == 15 || (s.getCheckersOnTarget(Black) == 15)) { return(true); } return(false); }
internal GameBoardState GetBoardState() { Task <GameBoardState> task = Task.Run(async() => { return(await _server.Proxy.Invoke <GameBoardState>("GetGameBoard", _gameKey)); }); _gameBoard = task.Result; return(_gameBoard); }
private void DoMove(GameBoardState gameBoard) { Move move; move = GetRandomMove(gameBoard, game.player1); gameBoard.Move(move); move = GetRandomMove(gameBoard, game.player2); gameBoard.Move(move); }
public void XmlifyGameBoardState() { GameBoardState state = new GameBoardState(BackgammonGame.DefaultGameBoard, 0, 0, 0, 0); string expected = "<gameboard><board>-2 0 0 0 0 5 0 3 0 0 0 -5 5 0 0 0 -3 0 -5 0 0 0 0 2</board>" + "<whiteGoal>0</whiteGoal><whiteBar>0</whiteBar><blackGoal>0</blackGoal><blackBar>0</blackBar></gameboard>"; string xml = UpdateCreatorParser.CreateXmlForGameBoardState(state, "gameboard"); GameBoardState parsedState = UpdateCreatorParser.ParseGameBoardState(xml); Assert.AreEqual(expected, xml); }
/// <summary> /// Method used to switch between players /// </summary> public void SetNextPlayer() { if (CurrentRoundState == GameBoardState.PlayerXTurn) { CurrentRoundState = GameBoardState.PlayerOTurn; } else { CurrentRoundState = GameBoardState.PlayerXTurn; } }
public void NewGame(Player p1, Player p2, int x, int y) { if (p1 != null && p2 != null) { if (!p1.Username.Equals(p2.Username)) { BoardState = new GameBoardState(p1, p2, x, y); GameStarted(); } } }
public static void UpdateWeights(GameBoardState st, GameBoardState st1, CheckerColor c) { color = c; UpdateF(st); DefineEligibilityTraces(st); ParameterUpdate(st, st1); if (double.IsNaN(EligibilityTraces[3])) { throw new Exception(); } }
private static double EvaluationFunction(GameBoardState st) {// Source: http://modelai.gettysburg.edu/2013/tdgammon/pa2.pdf UpdateF(st); double sum = 0; for (int i = 0; i < theta.Length; i++) { sum = sum + theta[i] * F[i]; } return(sum); }
private static double DifferenceFunction(GameBoardState st, GameBoardState st1) { double v = ValueFunction(st); if (!GameOver(st)) { return(ValueFunction(st1) - v); } double z = (st.getCheckersOnTarget(White) == 15) ? 1 : 0; return(z - v); }
private void ChangeToState(GameBoardState newState) { if (_states[_currentGameBoardState] != null) { _states[_currentGameBoardState].Exit(); } _currentGameBoardState = newState; if (_states[_currentGameBoardState] != null) { _states[_currentGameBoardState].Enter(); } Debug.Log(string.Format("Change to new state:{0}", _currentGameBoardState.ToString())); }
private static void UpdateF(GameBoardState st) { F = new int[8] { -st.getCheckersOnBar(White), st.getCheckersOnBar(Black), st.getCheckersOnTarget(White), -st.getCheckersOnTarget(Black), -st.capturableCheckers(White), st.capturableCheckers(Black), -st.pip(White), st.pip(Black) }; }
public void XmlifyGameBoardState2() { int[] mainBoard = new int[] { -2, 0, 0, 0, 0, 3, 0, 3, 0, 0, 0, -5, 5, 0, 0, 0, -1, 0, -5, 0, 0, 0, 0, 2 }; GameBoardState state = new GameBoardState(mainBoard, 1, 1, 1, 1); string expected = "<gameboard><board>-2 0 0 0 0 3 0 3 0 0 0 -5 5 0 0 0 -1 0 -5 0 0 0 0 2</board>" + "<whiteGoal>1</whiteGoal><whiteBar>1</whiteBar><blackGoal>-1</blackGoal><blackBar>-1</blackBar></gameboard>"; string xml = UpdateCreatorParser.CreateXmlForGameBoardState(state, "gameboard"); GameBoardState parsedState = UpdateCreatorParser.ParseGameBoardState(xml); Assert.AreEqual(expected, xml); Assert.AreEqual(state, parsedState); }
/// <summary> /// Clear the board by setting enum values to an empty string /// </summary> public void InitializeGameboard() { CurrentRoundState = GameBoardState.NewRound; //clear off gameboard to start a game for (int row = 0; row < MAX_NUMBER_OF_ROWS_COLUMNS; row++) { for (int column = 0; column < MaxNumberOfRowsColumns; column++) { CurrentBoard[row][column] = PLAYER_PIECE_NONE; //sets all the gamebooard buttons to empty strings } } }
private bool TryTie(GameBoardMark[,] gameBoard, out GameBoardState gameBoardState) { foreach (GameBoardMark gameBoardMark in gameBoard) { if (gameBoardMark == GameBoardMark.Empty) { gameBoardState = GameBoardState.Active; return(false); } } gameBoardState = GameBoardState.Tie; return(true); }
public void UpdateView() { if (Controller.BoardState == null) { squareGrid.Controls.Clear(); } else if (!Controller.BoardState.Equals(BoardState)) { BoardState = Controller.BoardState; CreateBoard(); Status.ShowStatus("Game started!"); Enabled = true; } }
public void InitializeGameboard() { CurrentState = GameBoardState.NewGame; // // Set all "Cards" on the game board to spaces to get ready for play // for (int row = 0; row < 6; row++) { for (int column = 0; column < 5; column++) { CurrentBoard[row][column] = ""; } } }
public bool MakeMove(Move move) { if (!moveValidator.IsValidMove(move, GameState, GameBoard)) { return(false); } gameBoard.PlaceMarker(move); GameBoardState gameBoardState = gameBoardAnalyzer.AnalyzeGameBoard(GameBoard); UpdateGameState(gameBoardState); return(true); }
void Awake() { m_Instance = this; m_State = GameBoardState.GameStopped; }