Update example

This commit is contained in:
Pranav Gaddamadugu 2022-09-17 20:40:27 +02:00
parent 8aa968ab1d
commit 159482e3c5

View File

@ -51,104 +51,104 @@ function main(public player: u8, row: u8, col: u8, board: Board) -> (Board, u8)
console.assert(player == 1u8 || player == 2u8); // 1 for X, 2 for O
console.assert(1u8 <= row && row <= 3u8);
console.assert(1u8 <= col && col <= 3u8);
let new: Board = board;
let updated: Board = board;
// This will work better when circuit assignment is supported.
if row == 1u8 && col == 1u8 && new.r1.e1 == 0u8 {
new = Board {
if row == 1u8 && col == 1u8 && updated.r1.e1 == 0u8 {
updated = Board {
r1: Row {
e1: player,
e2: new.r1.e2,
e3: new.r1.e3
e2: updated.r1.e2,
e3: updated.r1.e3
},
r2: new.r2,
r3: new.r3
r2: updated.r2,
r3: updated.r3
};
} else if row == 1u8 && col == 2u8 && new.r1.e2 == 0u8 {
new = Board {
} else if row == 1u8 && col == 2u8 && updated.r1.e2 == 0u8 {
updated = Board {
r1: Row {
e1: new.r1.e1,
e1: updated.r1.e1,
e2: player,
e3: new.r1.e3
e3: updated.r1.e3
},
r2: new.r2,
r3: new.r3
r2: updated.r2,
r3: updated.r3
};
} else if row == 1u8 && col == 3u8 && new.r1.e3 == 0u8 {
new = Board {
} else if row == 1u8 && col == 3u8 && updated.r1.e3 == 0u8 {
updated = Board {
r1: Row {
e1: new.r1.e1,
e2: new.r1.e2,
e1: updated.r1.e1,
e2: updated.r1.e2,
e3: player
},
r2: new.r2,
r3: new.r3
r2: updated.r2,
r3: updated.r3
};
} else if row == 2u8 && col == 1u8 && new.r2.e1 == 0u8 {
new = Board {
r1: new.r1,
} else if row == 2u8 && col == 1u8 && updated.r2.e1 == 0u8 {
updated = Board {
r1: updated.r1,
r2: Row {
e1: player,
e2: new.r2.e2,
e3: new.r2.e3
e2: updated.r2.e2,
e3: updated.r2.e3
},
r3: new.r3
r3: updated.r3
};
} else if row == 2u8 && col == 2u8 && new.r2.e2 == 0u8 {
new = Board {
r1: new.r1,
} else if row == 2u8 && col == 2u8 && updated.r2.e2 == 0u8 {
updated = Board {
r1: updated.r1,
r2: Row {
e1: new.r2.e1,
e1: updated.r2.e1,
e2: player,
e3: new.r2.e3
e3: updated.r2.e3
},
r3: new.r3
r3: updated.r3
};
} else if row == 2u8 && col == 3u8 && new.r2.e3 == 0u8 {
new = Board {
r1: new.r1,
} else if row == 2u8 && col == 3u8 && updated.r2.e3 == 0u8 {
updated = Board {
r1: updated.r1,
r2: Row {
e1: new.r2.e1,
e2: new.r2.e2,
e1: updated.r2.e1,
e2: updated.r2.e2,
e3: player
},
r3: new.r3
r3: updated.r3
};
} else if row == 3u8 && col == 1u8 && new.r3.e1 == 0u8 {
new = Board {
r1: new.r1,
r2: new.r2,
} else if row == 3u8 && col == 1u8 && updated.r3.e1 == 0u8 {
updated = Board {
r1: updated.r1,
r2: updated.r2,
r3: Row {
e1: player,
e2: new.r3.e2,
e3: new.r3.e3
e2: updated.r3.e2,
e3: updated.r3.e3
}
};
} else if row == 3u8 && col == 2u8 && new.r3.e2 == 0u8 {
new = Board {
r1: new.r1,
r2: new.r2,
} else if row == 3u8 && col == 2u8 && updated.r3.e2 == 0u8 {
updated = Board {
r1: updated.r1,
r2: updated.r2,
r3: Row {
e1: new.r3.e1,
e1: updated.r3.e1,
e2: player,
e3: new.r3.e3
e3: updated.r3.e3
}
};
} else if row == 3u8 && col == 3u8 && new.r3.e3 == 0u8 {
new = Board {
r1: new.r1,
r2: new.r2,
} else if row == 3u8 && col == 3u8 && updated.r3.e3 == 0u8 {
updated = Board {
r1: updated.r1,
r2: updated.r2,
r3: Row {
e1: new.r3.e1,
e2: new.r3.e2,
e1: updated.r3.e1,
e2: updated.r3.e2,
e3: player
}
};
}
if win(new, 1u8) {
return (new, 1u8);
} else if win(new, 2u8) {
return (new, 2u8);
if win(updated, 1u8) {
return (updated, 1u8);
} else if win(updated, 2u8) {
return (updated, 2u8);
} else {
return (new, 0u8);
return (updated, 0u8);
}
}