-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
29 lines (27 loc) · 927 Bytes
/
Copy pathscript.js
File metadata and controls
29 lines (27 loc) · 927 Bytes
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
var board=[];
var userChoice
var currentTurn
function minmax(){
this.minPlayer=1;
this.maxPlayer=2;
}
/*Setting the min and max values once we get the choice from the user*/
minmax.prototype.setMineMax=function(min,max){
this.minPlayer=min;
this.maxPlayer=max;
}
/*Copying the current configuration of the board and returning it. We do this since we need more have to operate on individual board instances on deeper depths*/
minmax.prototype.copyBoard=function(board){
return board.slice(0);
}
/*This function checks if a position is free on the board and makes the move. If the position is free, it makes a move and returns the new board, else returns the old board.*/
minmax.prototype.makeMove=function(position,board,player){
if(board[position]==0){
var newBoard=this.copyBoard(board);
newBoard[position]=player;
return newBoard;
}
else{
return null;
}
}