private void player2Worker_DoWork(object sender, DoWorkEventArgs e) { Random rnd = new Random(); State[,] layout = Program.MainForm.Login("Player 2"); GameState initialState = Program.MainForm.GetStatus(1); IAgent agent = new AlphaBetaAgent(p2Debug); ClientGameState myState = new ClientGameState(layout, initialState, 1); myState.currentTick = -1; #if DEBUG p2Debug.UpdateState(myState); Application.DoEvents(); #endif while (player2Worker.CancellationPending == false) { GameState curState = Program.MainForm.GetStatus(1); if (curState.events.blockEvents.Count > 0) { p2Debug.AddLog("Player 2 received " + curState.events.blockEvents.Count + " unseen block events"); myState.ProcessEvents(curState.events); } if (curState.currentTick > myState.currentTick) { myState = new ClientGameState(myState.blocks, curState, 1); myState.ProcessEvents(curState.events); #if DEBUG p2Debug.UpdateState(myState); Application.DoEvents(); #endif RandomAgent(rnd, myState, p2Debug); } Thread.Sleep(100); } }
private void player1Worker_DoWork(object sender, DoWorkEventArgs e) { Random rnd = new Random(); State[,] layout = Program.MainForm.Login("Player 1"); GameState initialState = Program.MainForm.GetStatus(0); IAgent agent = new AlphaBetaAgent(p1Debug); ClientGameState myState = new ClientGameState(layout, initialState, 0); myState.currentTick = -1; #if DEBUG p1Debug.UpdateState(myState); Application.DoEvents(); #endif while (player1Worker.CancellationPending == false) { GameState curState = Program.MainForm.GetStatus(0); if (curState.events.blockEvents.Count > 0) { p1Debug.AddLog("Player 1 received " + curState.events.blockEvents.Count + " unseen block events"); myState.ProcessEvents(curState.events); } if (curState.currentTick > myState.currentTick) { myState = new ClientGameState(myState.blocks, curState, 0); myState.ProcessEvents(curState.events); #if DEBUG p1Debug.UpdateState(myState); Application.DoEvents(); #endif ActionSet actions = agent.GetAction(myState); for (int idx = 0; idx < myState.Me.units.Count; idx++) { p1Debug.AddLog("Unit " + idx + " : Action=" + actions[idx]); Program.MainForm.SetAction(myState.myPlayerIdx, myState.players[myState.myPlayerIdx].units[idx].id, actions[idx]); } } Thread.Sleep(100); } }