<commit_before>package buzzbingo.model;

import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

@Component
public class GameBoard implements Serializable {
  String playerName;
  String gameName;
  String gameBoardName;
  List<String> words = new ArrayList<>();
  List<GameSquare> board = new ArrayList<>();
  Integer numHits = 0;

  private Integer dimension = 5;
  private Integer gameSize = dimension*dimension;

  public GameBoard() {
  }

  public GameBoard(String playerName, String gameName, Set<String> words) {
    //need to pass in the words of the game
    System.out.println("creating game board for " + playerName);
    this.playerName = playerName;
    this.gameName = gameName;
    gameBoardName = this.gameName + this.playerName;

    setWordlist(words);
    buildBoard();
  }

  public GameBoard buildBoard() {
    System.out.println("building board");
    for( int i = 0; i< gameSize; i++){
      if (i == gameSize/2) {
        //add middle free space
        board.add(new GameSquare("FREE", true));
      } else {
        board.add(new GameSquare(words.get(i)));
      }
    }
    return this;
  }

  public TurnResult toggleSquare(Integer index) {
    if (index >= gameSize || index < 0) return TurnResult.INVALID;
    GameSquare gameSquare = board.get(index);

    if (gameSquare.isMarked()) {
      gameSquare.setMarked(false);
      numHits--;
    } else if (!gameSquare.isMarked()) {
      gameSquare.setMarked(true);
      numHits++;
      if (hasBingo()) return TurnResult.GAMEOVER;
    }
    return TurnResult.GAMENOTOVER;
  }

  private void setWordlist(Set<String> words) {
    List<String> listwords = new ArrayList<>(words);
    while (listwords.size() < 24){
      // If there are less than 24 words, double until there are more.
      listwords.addAll(listwords);
    }
    Collections.shuffle(listwords);
    if (listwords.size() > gameSize) {
      listwords = listwords.subList(0, gameSize);
    }
    this.words = listwords;
    System.out.println("words: " + this.words);
  }

  public Boolean hasBingo() {
    //returns true if board is bingo, false otherwise
    if (numHits < 5) return false;
    if (numHits > 19) return true;
    //TODO: algorithm for determining winner
    //check all horiz
    //check all vert
    //check criss cross
    return false;
  }

  public String getPlayerName() {
    return playerName;
  }

  public void setPlayerName(String playerName) {
    this.playerName = playerName;
  }

  public String getGameName() {
    return gameName;<commit_msg>fix(gameboard): serialization of list of words<commit_after>package buzzbingo.model;

import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;

@Component
public class GameBoard implements Serializable {
  String playerName;
  String gameName;
  String gameBoardName;
  List<String> words = new ArrayList<>();
  List<GameSquare> board = new ArrayList<>();
  Integer numHits = 0;

  private Integer dimension = 5;
  private Integer gameSize = dimension*dimension;

  public GameBoard() {
  }

  public GameBoard(String playerName, String gameName, Set<String> words) {
    //need to pass in the words of the game
    System.out.println("creating game board for " + playerName);
    this.playerName = playerName;
    this.gameName = gameName;
    gameBoardName = this.gameName + "-" + this.playerName;

    setWordlist(words);
    buildBoard();
  }

  public GameBoard buildBoard() {
    System.out.println("building board");
    for( int i = 0; i< gameSize; i++){
      if (i == gameSize/2) {
//        add middle free space
        board.add(new GameSquare("FREE", true));
      } else {
        board.add(new GameSquare(words.get(i)));
      }
    }
    return this;
  }

  public TurnResult toggleSquare(Integer index) {
    if (index >= gameSize || index < 0) return TurnResult.INVALID;
    GameSquare gameSquare = board.get(index);

    if (gameSquare.isMarked()) {
      gameSquare.setMarked(false);
      numHits--;
    } else if (!gameSquare.isMarked()) {
      gameSquare.setMarked(true);
      numHits++;
      if (hasBingo()) return TurnResult.GAMEOVER;
    }
    return TurnResult.GAMENOTOVER;
  }

  private void setWordlist(Set<String> words) {
    List<String> listwords = new ArrayList<>();
    listwords.addAll(words);
    while (listwords.size() < 24){
      // If there are less than 24 words, double until there are more.
      listwords.addAll(listwords);
    }
    Collections.shuffle(listwords);
    if (listwords.size() > gameSize) {
      ArrayList<String> newWords = new ArrayList<>();
      newWords.addAll(listwords.subList(0, gameSize));
      listwords = newWords;
    }
    this.words = listwords;
    System.out.println("words: " + this.words);
  }

  public Boolean hasBingo() {
    //returns true if board is bingo, false otherwise
    if (numHits < 5) return false;
    if (numHits > 19) return true;
    //TODO: algorithm for determining winner
    //check all horiz
    //check all vert
    //check criss cross
    return false;
  }

  public String getPlayerName() {
    return playerName;
  }

  public void setPlayerName(String playerName) {
    this.playerName = playerName;
  }

  public String getGameName() {
    return gameName;
{'fraction_non_alphanumeric': 0.11407053637031594, 'fraction_numerical': 0.004775900073475386, 'mean_word_length': 3.143835616438356, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, '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': '4254374', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1654, 'n_words': 452}