<commit_before>package moves

var Start = [64]int16{
  B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK,
  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  W_PAWN, W_PAWN,   W_PAWN,   W_PAWN,  W_PAWN, W_PAWN,   W_PAWN,   W_PAWN,
  W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK}

func Add(board [64]int16, move Move) [64]int16 {
  board[move.from] = EMPTY
  board[move.to] = move.piece
  return board
}

func Remove(board [64]int16, move Move) [64]int16 {
  board[move.to] = move.prev
  board[move.from] = move.piece
  return board
}
/*
func Load(fen string) [64]int16 {
  return []int16{}
}

func Save(board [64]int16) string {
  return ""
}
*/
func Perft(depth int) int {
  var board = Start
  var nodes int = 0

  var moves = Generate(board, COLOR_WHITE)

  if depth == 0 {
    return 1
  }

  if depth == 1 {
    return len(moves)
  }

  for _, move := range moves {
    Add(board, move)
    nodes += Perft(depth - 1)
    Remove(board, move)
  }

  return nodes
}<commit_msg>feat: restore previous piece on undo move<commit_after>package moves

import "fmt"

var Start = [64]int16{
  B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK,
  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  W_PAWN, W_PAWN,   W_PAWN,   W_PAWN,  W_PAWN, W_PAWN,   W_PAWN,   W_PAWN,
  W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK}

var Test = [64]int16{
  B_ROOK, B_KNIGHT, B_BISHOP, B_QUEEN, B_KING, B_BISHOP, B_KNIGHT, B_ROOK,
  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,  B_PAWN, B_PAWN,   B_PAWN,   B_PAWN,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    EMPTY,   EMPTY,  EMPTY,    EMPTY,    EMPTY,
  EMPTY,  EMPTY,    EMPTY,    W_PAWN,  EMPTY,  EMPTY,    EMPTY,    EMPTY,
  W_PAWN, W_PAWN,   W_PAWN,   EMPTY,   W_PAWN, W_PAWN,   W_PAWN,   W_PAWN,
  W_ROOK, W_KNIGHT, W_BISHOP, W_QUEEN, W_KING, W_BISHOP, W_KNIGHT, W_ROOK}

func Add(board [64]int16, move Move) [64]int16 {
  board[move.From] = EMPTY
  board[move.To] = move.Piece
  return board
}

func Remove(board [64]int16, move Move) [64]int16 {
  board[move.To] = move.Prev
  board[move.From] = move.Piece
  return board
}
/*
func Load(fen string) [64]int16 {
  return []int16{}
}

func Save(board [64]int16) string {
  return ""
}
*/
func  Perft(board [64]int16, depth int, color int16) int {
  var nodes int = 0
  var captures int = 0

  var moves = Generate(board, color)

  // stats
  for _, move := range moves {
    if move.Capture {
      fmt.Println("capture", move.Capture)
      captures += 1
    }
  }

  if color == COLOR_WHITE {
    color = COLOR_BLACK
  } else {
    color = COLOR_WHITE
  }

  if depth == 1 {
    return len(moves)
  }

  for _, move := range moves {
    // make move
    Add(board, move)

    // look deeper
    nodes += Perft(board, depth - 1, color)

    // undo move
    Remove(board, move)
  }

  return nodes
}
{'fraction_non_alphanumeric': 0.12, 'fraction_numerical': 0.021917808219178082, 'mean_word_length': 2.756172839506173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4351725', 'n_tokens_mistral': 1802, 'n_tokens_neox': 1625, 'n_words': 386}