Send previous moves.
(websocket, game)
| 27 | |
| 28 | |
| 29 | async def replay(websocket, game): |
| 30 | """ |
| 31 | Send previous moves. |
| 32 | |
| 33 | """ |
| 34 | # Make a copy to avoid an exception if game.moves changes while iteration |
| 35 | # is in progress. If a move is played while replay is running, moves will |
| 36 | # be sent out of order but each move will be sent once and eventually the |
| 37 | # UI will be consistent. |
| 38 | for player, column, row in game.moves.copy(): |
| 39 | event = { |
| 40 | "type": "play", |
| 41 | "player": player, |
| 42 | "column": column, |
| 43 | "row": row, |
| 44 | } |
| 45 | await websocket.send(json.dumps(event)) |
| 46 | |
| 47 | |
| 48 | async def play(websocket, game, player, connected): |