<commit_before>#include "Pattern.h"

#include <assert.h>

#include "Board.h"

static char pointToCharMap[] = { '_', 'W', 'B', 'O' };

Pattern::Pattern() : hash(""),
  goodMoves(std::vector<std::pair<char, char>>()) {

}

char Pattern::pointToChar(Point* p) {
  return pointToCharMap[p->color];
  /*
  if (p == NULL)
    return 'O';
  if (p->color == White)
    return 'W';
  else if (p->color == Black)
    return 'B';
  else if (p->color == Empty)
    return '_';
  else if (p->color == OutOfBounds)
    return 'O';
  else assert(false);
  */
}
/*
Pattern::Pattern(Point* p) : hash(""),
  goodMoves(std::vector<std::pair<char, char>>()) {

  if (*p == Point(BOARD_SIZE, BOARD_SIZE))
    return;
  
  Point* s = p->south;
  Point* sw = s->west;
  Point* se = s->east;
  Point* w = p->west;
  Point* e = p->east;
  Point* n = p->north;
  Point* nw = n->west;
  Point* ne = n->east;
  
  hash += pointToChar(sw);
  hash += pointToChar(s);
  hash += pointToChar(se);
  hash += pointToChar(w);
  hash += pointToChar(p);
  hash += pointToChar(e);
  hash += pointToChar(nw);
  hash += pointToChar(n);
  hash += pointToChar(ne);

}*/

Pattern::~Pattern() {

}

bool operator==(const Pattern &p1, const Pattern &p2) {
  if (p1.hash.compare(p2.hash))
    return false;
  return true;
}

void Pattern::invertColor() {
  std::string newHash = "";
  for (char c : hash) {
    if (c == 'B')
      c = 'W';
    else if (c == 'W')
      c = 'B';
    newHash += c;
  }
  hash = newHash;
}

Point* Pattern::getRandomGoodMove(Board* b, Point& move, std::default_random_engine& engine) {
  if (goodMoves.size() == 0)
    return NULL;
  std::uniform_int_distribution<> dist(0, (int)goodMoves.size()-1);
  int choice = dist(engine);
  return &b->positions[goodMoves[choice].first+move.row][goodMoves[choice].second+move.color];
}

std::vector<Point*> Pattern::getGoodMoves(Board* b, Point& move) {
  std::vector<Point*> movesToReturn;
  for (auto p : goodMoves) {
    movesToReturn.push_back(&b->positions[p.first+move.row][p.second+move.column]);
  }
  return movesToReturn;
}

char Pattern::getRandomColor(std::default_random_engine& engine) {
  std::uniform_int_distribution<> dist(0, 3);
  int i = dist(engine);
  char randomColor;
  if (i == 0) {
    randomColor = 'B';
  } else if (i == 1) {
    randomColor = 'W';
  } else if (i == 2) {
    randomColor = '_';
  } else {
    randomColor = 'O';
  }
  return randomColor;<commit_msg>Fixed a problem with Pattern::getRandomGoodMove that had color being used in place of column<commit_after>#include "Pattern.h"

#include <assert.h>

#include "Board.h"

static char pointToCharMap[] = { '_', 'W', 'B', 'O' };

Pattern::Pattern() : hash(""),
  goodMoves(std::vector<std::pair<char, char>>()) {

}

char Pattern::pointToChar(Point* p) {
  return pointToCharMap[p->color];
  /*
  if (p == NULL)
    return 'O';
  if (p->color == White)
    return 'W';
  else if (p->color == Black)
    return 'B';
  else if (p->color == Empty)
    return '_';
  else if (p->color == OutOfBounds)
    return 'O';
  else assert(false);
  */
}
/*
Pattern::Pattern(Point* p) : hash(""),
  goodMoves(std::vector<std::pair<char, char>>()) {

  if (*p == Point(BOARD_SIZE, BOARD_SIZE))
    return;
  
  Point* s = p->south;
  Point* sw = s->west;
  Point* se = s->east;
  Point* w = p->west;
  Point* e = p->east;
  Point* n = p->north;
  Point* nw = n->west;
  Point* ne = n->east;
  
  hash += pointToChar(sw);
  hash += pointToChar(s);
  hash += pointToChar(se);
  hash += pointToChar(w);
  hash += pointToChar(p);
  hash += pointToChar(e);
  hash += pointToChar(nw);
  hash += pointToChar(n);
  hash += pointToChar(ne);

}*/

Pattern::~Pattern() {

}

bool operator==(const Pattern &p1, const Pattern &p2) {
  if (p1.hash.compare(p2.hash))
    return false;
  return true;
}

void Pattern::invertColor() {
  std::string newHash = "";
  for (char c : hash) {
    if (c == 'B')
      c = 'W';
    else if (c == 'W')
      c = 'B';
    newHash += c;
  }
  hash = newHash;
}

Point* Pattern::getRandomGoodMove(Board* b, Point& move, std::default_random_engine& engine) {
  if (goodMoves.size() == 0)
    return NULL;
  std::uniform_int_distribution<> dist(0, (int)goodMoves.size()-1);
  int choice = dist(engine);
  return &b->positions[goodMoves[choice].first+move.row][goodMoves[choice].second+move.column];
}

std::vector<Point*> Pattern::getGoodMoves(Board* b, Point& move) {
  std::vector<Point*> movesToReturn;
  for (auto p : goodMoves) {
    movesToReturn.push_back(&b->positions[p.first+move.row][p.second+move.column]);
  }
  return movesToReturn;
}

char Pattern::getRandomColor(std::default_random_engine& engine) {
  std::uniform_int_distribution<> dist(0, 3);
  int i = dist(engine);
  char randomColor;
  if (i == 0) {
    randomColor = 'B';
  } else if (i == 1) {
    randomColor = 'W';
  } else if (i == 2) {
    randomColor = '_';
  } else {
    randomColor = 'O';
  }
  return randomColor;
{'fraction_non_alphanumeric': 0.19129019129019129, 'fraction_numerical': 0.004884004884004884, 'mean_word_length': 3.619360902255639, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 51, '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': '44202', 'n_tokens_mistral': 1887, 'n_tokens_neox': 1861, 'n_words': 422}