Skip to content

Instantly share code, notes, and snippets.

View byanofsky's full-sized avatar

Brandon Yanofsky byanofsky

View GitHub Profile
@byanofsky
byanofsky / lexer_by_chatgpt.c
Last active April 23, 2023 16:54
A lexer product by ChatGPT
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAX_TOKEN_LENGTH 100
enum TokenType
{
TOKEN_INTEGER,
TOKEN_VARIABLE,
@byanofsky
byanofsky / default_settings.py
Created August 8, 2017 15:30
Flask configuration which allows different settings depending on the environment
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 July 6, 2017 15:35
Minimax algorithm with alpha beta pruning
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 July 6, 2017 15:15
Evaluate the best move using Minimax
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 July 4, 2017 17:23
Calculates the best move looking one move ahead
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
@byanofsky
byanofsky / chess-ai-position-evaluation.js
Created July 4, 2017 17:14
Evaluates position of board
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
};