public void PlayOneMove() { // Debug = ""; ServerGameState latest = States[States.Count() - 1]; if (latest.GameHasEnded()) { return; } // ServerGameState state = new ServerGameState(latest); States.Add(state); StatePointer = States.Count() - 1; // for (int i = 0; i < PlayerSetup.Length; i++) { //End of game if (state.GameHasEnded()) { continue; } //Skip if player is dead if (state.Players[i][0].X < 0) { continue; } // string move = ""; if (PlayerSetup[i] == 'H') { debug("human.GetMove()"); move = human.GetMove(state.GetSerialization(i)); } else if (PlayerSetup[i] == 'P') { debug("player.GetMove()"); move = Players[i].GetMove(state.GetSerialization(i)); state.PlayerDebug += Players[i].Debug + "\n"; } state.Moves += move + "\n"; // debug("updateGameState()"); updateGameState(state, move, i); } // state.ServerDebug = Debug; }
public TronServer() { if (Directions.Count() == 0) { Directions.Add("UP", new Point(0, -1)); Directions.Add("DOWN", new Point(0, 1)); Directions.Add("RIGHT", new Point(1, 0)); Directions.Add("LEFT", new Point(-1, 0)); } human = new TronHuman(0); Players[0] = new TronPlayer(PlayerSetup.Length, 0); Players[1] = new TronPlayer(PlayerSetup.Length, 1); Players[2] = new TronPlayer(PlayerSetup.Length, 2); Players[3] = new TronPlayer(PlayerSetup.Length, 3); States.Add(ServerGameState.Initial()); }
private void update() { // int Round = Server.StatePointer; lblTurn.Text = (Round * 2).ToString() + "/400"; // ServerGameState state = Server.GetCurrent(); picState.Image = state.GetState(); picState.Invalidate(); txtGameState.Text = state.GetBoard().Replace("\n", "\r\n"); txtPlayer.Text = state.PlayerDebug.Replace("\n", "\r\n"); txtServer.Text = state.ServerDebug.Replace("\n", "\r\n"); txtMoves.Text = state.Moves.Replace("\n", "\r\n"); txtResults.Text = state.Results.Replace("\n", "\r\n"); // lblScore.Text = "--"; }
private void updateGameState(ServerGameState state, string move, int playerNumber) { //Update path List <Point> trail = state.Players[playerNumber]; Point current = trail[trail.Count() - 1]; if (Directions.ContainsKey(move.Trim())) { Point direction = Directions[move.Trim()]; Point next = new Point(current.X + direction.X, current.Y + direction.Y); if (next.X < W && next.X >= 0 && next.Y < H && next.Y >= 0) { if (state.Board[next.X, next.Y] == '.') { state.Board[next.X, next.Y] = playerNumber.ToString()[0]; trail.Add(next); state.Results += "Player " + playerNumber + " moved to " + next.X + "," + next.Y + "\n"; return; } } } //Losing char p = playerNumber.ToString()[0]; for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { if (state.Board[i, j] == p) { state.Board[i, j] = '.'; } } } state.Players[playerNumber] = new List <Point>() { new Point(-1, -1) }; state.Results += "Player " + playerNumber + " lost"; }
public ServerGameState(ServerGameState state) { // for (int i = 0; i < W; i++) { for (int j = 0; j < H; j++) { Board[i, j] = state.Board[i, j]; } } // Players = new List <Point> [state.Players.Length]; for (int k = 0; k < Players.Length; k++) { List <Point> trail = state.Players[k]; List <Point> newTrail = new List <Point>(); foreach (Point p in trail) { newTrail.Add(p); } Players[k] = newTrail; } }