Skip to content

Commit b82ecc0

Browse files
Final (we can hope) premove cleanup
1 parent 207ea31 commit b82ecc0

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

api/abstractplay.ts

Lines changed: 5 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,7 +3400,6 @@ async function submitMove(userid: string, pars: { id: string, move: string, draw
34003400

34013401
// Parse explorations if fetched (for premove processing)
34023402
let opponentExploration: Exploration[] | null = null;
3403-
let myExploration: Exploration[] | null = null;
34043403
if (opponentExplorationData?.Item?.tree) {
34053404
try {
34063405
opponentExploration = JSON.parse(opponentExplorationData.Item.tree as string);
@@ -4759,49 +4758,24 @@ async function saveExploration(userid: string, pars: { public: boolean, game: st
47594758

47604759
async function getExploration(userid: string, pars: { game: string; move: number }) {
47614760
const work: Promise<any>[] = [];
4761+
let exploration;
47624762
try {
4763-
// get exploration you did while looking at this position in a previous visit to the game
4764-
work.push(ddbDocClient.send(
4763+
// get exploration. At pars.move. submitMove now takes care of moving exploration to the current game state.
4764+
exploration = await ddbDocClient.send(
47654765
new GetCommand({
47664766
TableName: process.env.ABSTRACT_PLAY_TABLE,
47674767
Key: {
47684768
"pk": "GAMEEXPLORATION#" + pars.game,
47694769
"sk": userid + "#" + pars.move
47704770
},
47714771
})
4772-
));
4773-
// also get exploration you did while you opponent was on move, or if it is his move, the exploration you did for your last move.
4774-
if (pars.move > 0) {
4775-
work.push(ddbDocClient.send(
4776-
new GetCommand({
4777-
TableName: process.env.ABSTRACT_PLAY_TABLE,
4778-
Key: {
4779-
"pk": "GAMEEXPLORATION#" + pars.game,
4780-
"sk": userid + "#" + (pars.move - 1)
4781-
},
4782-
})
4783-
));
4784-
}
4785-
// and exploration you did when it was last your move. No need to further back because that exploration would have been merged when it was
4786-
// last your move (unless you turned off exploration for that move, but...)
4787-
if (pars.move > 1) {
4788-
work.push(ddbDocClient.send(
4789-
new GetCommand({
4790-
TableName: process.env.ABSTRACT_PLAY_TABLE,
4791-
Key: {
4792-
"pk": "GAMEEXPLORATION#" + pars.game,
4793-
"sk": userid + "#" + (pars.move - 2)
4794-
},
4795-
})
4796-
));
4797-
}
4772+
);
47984773
}
47994774
catch (error) {
48004775
logGetItemError(error);
48014776
return formatReturnError(`Unable to get exploration data for game ${pars.game} from table ${process.env.ABSTRACT_PLAY_TABLE}`);
48024777
}
4803-
const data = await Promise.all(work);
4804-
const trees = data.map((d: any) => d.Item);
4778+
const trees = [exploration.Item,,]; // return as an array as was done in the past. Not really needed, but makes transition safer.
48054779
return {
48064780
statusCode: 200,
48074781
body: JSON.stringify(trees),

0 commit comments

Comments
 (0)