Skip to content

Commit

Permalink
Add IsVictory logic into example code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindexus committed Dec 3, 2019
1 parent 35cb2be commit ef91329
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion docs/documentation/tutorial.md
Expand Up @@ -94,7 +94,30 @@ Let's also prevent players from being able to overwrite cells:
```js
// Return true if `cells` is in a winning configuration.
function IsVictory(cells) {
...
const positions = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[2, 4, 6],
];

for (let pos of positions) {
const symbol = cells[pos[0]];
let winner = symbol;
for (let i of pos) {
if (cells[i] != symbol) {
winner = null;
break;
}
}
if (winner != null) return true;
}

return false;
}

// Return true if all `cells` are occupied.
Expand Down

0 comments on commit ef91329

Please sign in to comment.