-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
move-maker.js
36 lines (35 loc) · 1.37 KB
/
move-maker.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
Given a move and a board (an array of arrays), return true if the move is valid.
A move is represented by 2 numbers separated by a comma.
The first number is the row (1, 2 or 3) and the second number is the column (1, 2 or 3).
Some valid example moves are 1,3 and 2,2.
Some invalid examples are 0,1 and 2-1.
Also, a move can only be made in a free space ('_') on the board.
If the move is not valid:
- you can output 'Try again...'
- and then return false
Testing your function by calling it with some values. An example board is:
let board = [
['X', '_', '_'],
['_', 'X', '_'],
['O', 'O', 'X']
];
*/
function validateMove(move, board) {
// Implement this at the end if you have time, otherwise you can help your teammates!
return true;
}
/*
Given 3 parameters:
- a board (an array of arrays)
- a move (2 numbers separated by a comma)
- a player ('X' or 'O'):
Check that the move is valid using the validateMove function.
If the move is not valid, the function should just return false.
If the move is valid, the function should:
- Update the board with the player's value ('X' or 'O') in the correct position
- Return true
*/
export function makeMove(board, move, player) {
return false;
}