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