Package vrampal.connectfour.core

Examples of vrampal.connectfour.core.Board


    // Nothing to do.
  }

  @Override
  public int selectPlayColumn(Game game) {
    Board board = game.getBoard();
    int width = board.getWidth();
    List<Integer> bestMatchs = new ArrayList<>();
    double bestStat = -1000.0;

    for (int colIdx = 0; colIdx < width; colIdx++) {
      if (!board.isColumnFull(colIdx)) {
        GamesData candidate = currentData.getSubGame(colIdx);
        if (candidate != null) {
          double stat = getStat(candidate);
          if (stat > bestStat) {
            bestStat = stat;
View Full Code Here


  private static final Random RAND = new Random();

  @Override
  public int selectPlayColumn(Game game) {
    Board board = game.getBoard();
    int width = board.getWidth();

    int colIdx = RAND.nextInt(width);
    while (board.isColumnFull(colIdx)) {
      colIdx = RAND.nextInt(width);
    }

    return colIdx;
  }
View Full Code Here

    List<Player> inPlayers = in.getAllPlayers();
    nbPlayers = inPlayers.size();
    players = new PlayerData[nbPlayers];
    inPlayers.toArray(players);

    Board inBoard = in.getBoard();
    width = inBoard.getWidth();
    height = inBoard.getHeight();
    board = new char[width * height];
    for (int colIdx = 0; colIdx < width; colIdx++) {
      for (int rowIdx = 0; rowIdx < height; rowIdx++) {
        Player curCell = inBoard.getCell(colIdx, rowIdx);
        board[(colIdx * height) + rowIdx] = curCell.getLetter();
      }
    }

    status = in.getStatus();
View Full Code Here

  private static final BufferedReader IN = new BufferedReader(new InputStreamReader(System.in));

  @Override
  public int selectPlayColumn(Game game) {
    Board board = game.getBoard();
    int width = board.getWidth();
    int colIdx = 0;
    while ((colIdx < 1) || (colIdx > width)) {
      try {
        println("Now playing: " + game.getCurrentPlayer().getName());
        print("Type a column number [1.." + width + "]: ");
View Full Code Here

    }
    return retVal;
  }

  String printBoard(Game game) {
    Board board = game.getBoard();
    int height = board.getHeight();
    int width = board.getWidth();
    GameStatus status = game.getStatus();

    StringBuilder buff = new StringBuilder(1300);

    if (status == GameStatus.ONGOING) {
      buff.append("<tr>");
      for (int colIdx = 1; colIdx <= width; colIdx++) {
        buff.append("<td class=\"cfh\"><a href=\"?col=");
        buff.append(colIdx);
        buff.append("\">V</a></td>");
      }
      buff.append("</tr>");
    }

    for (int rowIdx = height; rowIdx > 0; rowIdx--) {
      buff.append("<tr>");
      for (int colIdx = 1; colIdx <= width; colIdx++) {
        Player content = board.getCell(colIdx - 1, rowIdx - 1);
        char c = content.getLetter();
        String clazz = "cfe";
        if (c == 'R') {
          clazz = "cfr";
        } else if (c == 'Y') {
View Full Code Here

  public void testPrintBoard() {
    Player player = mock(Player.class);
    when(player.getName()).thenReturn("Test player");
    when(player.getLetter()).thenReturn(' ');

    Board board = mock(Board.class);
    when(board.getWidth()).thenReturn(3);
    when(board.getHeight()).thenReturn(2);
    when(board.getCell(anyInt(), anyInt())).thenReturn(player);

    Game game = mock(Game.class);
    when(game.getStatus()).thenReturn(GameStatus.ONGOING);
    when(game.getBoard()).thenReturn(board);
View Full Code Here

TOP

Related Classes of vrampal.connectfour.core.Board

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.