MCPcopy Create free account
hub / github.com/codemistic/Web-Development / pickMove

Function pickMove

bot-human-tictactoe/script.js:34–72  ·  view source on GitHub ↗
(states,player)

Source from the content-addressed store, hash-verified

32})()
33const agent = (()=>{
34 const pickMove = (states,player)=>{
35 let bestMove
36 if(player == PLAYER_X){
37 let bestScore = -Infinity
38 for(let i=0;i<grid_side;i++){
39 for(j=0;j<grid_side;j++){
40 if(states[i][j] == 0){
41 states[i][j] = 1
42 score = minimax(states, 0,false)
43 states[i][j] = 0
44 if(score>bestScore){
45 bestScore = score
46 a = " "+i
47 b = " "+ j
48 bestMove = {i,j}
49 }
50 }
51 }
52 }
53 }
54 else{
55 let bestScore = Infinity
56 for(let i=0;i<grid_side;i++){
57 for(let j=0;j<grid_side;j++){
58 if(states[i][j]==0){
59 states[i][j] = -1
60 score = minimax(states,0,true)
61 states[i][j] = 0
62 if(score<bestScore){
63 bestScore = score
64 bestMove = {i,j}
65 }
66 }
67 }
68 }
69 }
70 return bestMove
71
72 }
73 const minimax = (states,depth, isMaximising) =>{
74 // console.log(""+states);
75 result = checkWinner(states)

Callers

nothing calls this directly

Calls 1

minimaxFunction · 0.85

Tested by

no test coverage detected