Added a readme.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
Homework that I did for an AI class that Harvard offered. Sadly I
|
||||
never got a chance to finish said class, but I figured these early projects
|
||||
would be worth archiving.
|
||||
@@ -38,7 +38,7 @@ function draw() {
|
||||
noLoop();
|
||||
}
|
||||
|
||||
function nextTurn() {
|
||||
function nextTurn() { //minimax
|
||||
let bestScore = players[currentPlayer] == 'X' ? -Infinity : Infinity;
|
||||
let move;
|
||||
|
||||
@@ -90,7 +90,6 @@ function minimaxPrune(board, alpha, beta, isMaximizing){
|
||||
board[i][j] = 'X';
|
||||
let score = minimaxPrune(board, alpha, beta, false);
|
||||
board[i][j] = '';
|
||||
|
||||
bestScore = max(score, bestScore);
|
||||
alpha = max(alpha, bestScore);
|
||||
|
||||
@@ -109,7 +108,7 @@ function minimaxPrune(board, alpha, beta, isMaximizing){
|
||||
board[i][j] = 'O';
|
||||
let score = minimaxPrune(board, alpha, beta, true);
|
||||
board[i][j] = '';
|
||||
|
||||
if (score > 1 || score < -1) print(score);
|
||||
bestScore = min(score, bestScore);
|
||||
beta = min(beta, bestScore);
|
||||
|
||||
@@ -162,7 +161,7 @@ function minimax(board, isMaximizing){
|
||||
|
||||
function checkWinner(board, showEnd = false){
|
||||
let winner = null;
|
||||
|
||||
// Horizontal
|
||||
for(let i = 0; i < 3; i++){
|
||||
if(board[i][0] == board[i][1] && board[i][1] == board[i][2] && board[i][0] != ''){
|
||||
winner = board[i][0];
|
||||
@@ -175,6 +174,7 @@ function checkWinner(board, showEnd = false){
|
||||
}
|
||||
}
|
||||
|
||||
// Vertical
|
||||
for(let i = 0; i < 3; i++){
|
||||
if(board[0][i] == board[1][i] && board[1][i] == board[2][i] && board[0][i] != ''){
|
||||
winner = board[0][i];
|
||||
@@ -186,7 +186,7 @@ function checkWinner(board, showEnd = false){
|
||||
if(showEnd) line(x, 0, x, width);
|
||||
}
|
||||
}
|
||||
|
||||
// Diagonal
|
||||
if(board[0][0] != '' && board[0][0] == board[1][1] && board[2][2] == board[0][0]){
|
||||
winner = board[0][0];
|
||||
if(showEnd) line(0, 0, width, width);
|
||||
|
||||
Reference in New Issue
Block a user