Skip to content

Instantly share code, notes, and snippets.

Avatar

Brandon Yanofsky byanofsky

View GitHub Profile
@byanofsky
byanofsky / default_settings.py
Created Aug 8, 2017
Flask configuration which allows different settings depending on the environment
View default_settings.py
import os
# Get environment, or set to development by default
app_env = os.environ.get('APPLICATION_ENVIRONMENT') or 'development'
# Settings applied to all environments
SECRET_KEY = 'development key'
# Settings applied to specific environments
if app_env == 'production':
@byanofsky
byanofsky / chess-ai-minimax-with-alpha-beta.js
Created Jul 6, 2017
Minimax algorithm with alpha beta pruning
View chess-ai-minimax-with-alpha-beta.js
var calcBestMove = function(depth, game, playerColor,
alpha=Number.NEGATIVE_INFINITY,
beta=Number.POSITIVE_INFINITY,
isMaximizingPlayer=true) {
// Base case: evaluate board
if (depth === 0) {
value = evaluateBoard(game.board(), playerColor);
return [value, null]
}
@byanofsky
byanofsky / chess-ai-minimax.js
Created Jul 6, 2017
Evaluate the best move using Minimax
View chess-ai-minimax.js
var calcBestMoveNoAB = function(depth, game, playerColor,
isMaximizingPlayer=true) {
// Base case: evaluate board
if (depth === 0) {
value = evaluateBoard(game.board(), playerColor);
return [value, null]
}
// Recursive case: search possible moves
var bestMove = null; // best move not set yet
@byanofsky
byanofsky / calc-best-move-one-move-ahead.js
Created Jul 4, 2017
Calculates the best move looking one move ahead
View calc-best-move-one-move-ahead.js
var calcBestMoveOne = function(playerColor) {
// List all possible moves
var possibleMoves = game.moves();
// Sort moves randomly, so the same move isn't always picked on ties
possibleMoves.sort(function(a, b){return 0.5 - Math.random()});
// exit if the game is over
if (game.game_over() === true || possibleMoves.length === 0) return;
// Search for move with highest value
View chess-ai-position-evaluation.js
var evaluateBoard = function(board, color) {
// Sets the value for each piece using standard piece value
var pieceValue = {
'p': 100,
'n': 350,
'b': 350,
'r': 525,
'q': 1000,
'k': 10000
};