public Board() { _slots = new Mycell[height][]; for (int i = 0; i < height; i++) { _slots[i] = new Mycell[width]; } }
public static void abMinimax(bool maximizeOrMinimize, Mycell color, int depth, Board board, out int move, out int score) { if (0 == depth) { move = -1; score = ScoreBoard(board); } else { int bestScore = maximizeOrMinimize?-10000000:10000000; int bestMove = -1; for (int column = 0; column < width; column++) { if (board._slots[0][column] != Mycell.Barren) { continue; } int rowFilled = dropDisk(board, column, color); if (rowFilled == -1) { continue; } int s = ScoreBoard(board); if (s == (maximizeOrMinimize?orangeWins:yellowWins)) { bestMove = column; bestScore = s; board._slots[rowFilled][column] = Mycell.Barren; break; } int moveInner, scoreInner; abMinimax(!maximizeOrMinimize, color == Mycell.Orange?Mycell.Yellow:Mycell.Orange, depth - 1, board, out moveInner, out scoreInner); board._slots[rowFilled][column] = Mycell.Barren; if (depth == maxDepth && g_debug) { Console.WriteLine("Depth {0}, placing on {1}, score:{2}", depth, column, scoreInner); } if (maximizeOrMinimize) { if (scoreInner >= bestScore) { bestScore = scoreInner; bestMove = column; } } else { if (scoreInner <= bestScore) { bestScore = scoreInner; bestMove = column; } } } move = bestMove; score = bestScore; } }
public static int dropDisk(Board board, int column, Mycell color) { for (int y=height-1; y>=0; y--) if (board._slots[width*(y)+column] == Mycell.Barren) { board._slots[width*(y)+column] = color; return y; } return -1; }
private void deleteInListCells(List <Cell> cells, Cell cell, Cell nextCell) { cells = cells.FindAll(Mycell => !Mycell.EqualsInValueAndHypothesis(cell) && !Mycell.EqualsInValueAndHypothesis(nextCell)); foreach (String hypothesisString in cell.hypothesis) { foreach (Cell tempCell in cells) { tempCell.hypothesis.Remove(hypothesisString); } } }
public static int dropDisk(Board board, int column, Mycell color) { for (int y = height - 1; y >= 0; y--) { if (board._slots[width * (y) + column] == Mycell.Barren) { board._slots[width * (y) + column] = color; return(y); } } return(-1); }
private int dropDisk(int[] board, int column, Mycell color) { for (int y = height - 1; y >= 0; y--) { if (board[width * (y) + column] == (int)Mycell.Barren) { board[width * (y) + column] = (int)color; return(y); } } return(-1); }
public static void abMinimax(bool maximizeOrMinimize, Mycell color, int depth, Board board, out int move, out int score) { if (0 == depth) { move = -1; score = ScoreBoard(board); } else { int bestScore=maximizeOrMinimize?-10000000:10000000; int bestMove=-1; for (int column=0; column<width; column++) { if (board._slots[width*(0)+column]!=Mycell.Barren) continue; int rowFilled = dropDisk(board, column, color); if (rowFilled == -1) continue; int s = ScoreBoard(board); if (s == (maximizeOrMinimize?orangeWins:yellowWins)) { bestMove = column; bestScore = s; board._slots[width*(rowFilled)+column] = Mycell.Barren; break; } int moveInner, scoreInner; if (depth>1) abMinimax(!maximizeOrMinimize, color==Mycell.Orange?Mycell.Yellow:Mycell.Orange, depth-1, board, out moveInner, out scoreInner); else { moveInner = -1; scoreInner = s; } board._slots[width*(rowFilled)+column] = Mycell.Barren; /* when loss is certain, avoid forfeiting the match, by shifting scores by depth... */ if (scoreInner == orangeWins || scoreInner == yellowWins) scoreInner -= depth * (int)color; if (depth == maxDepth && g_debug) Console.WriteLine("Depth {0}, placing on {1}, score:{2}", depth, column, scoreInner); if (maximizeOrMinimize) { if (scoreInner>=bestScore) { bestScore = scoreInner; bestMove = column; } } else { if (scoreInner<=bestScore) { bestScore = scoreInner; bestMove = column; } } } move = bestMove; score = bestScore; } }
public Board() { _slots = new Mycell[height][]; for(int i=0; i<height; i++) _slots[i] = new Mycell[width]; }
public static void abMinimax(bool maximizeOrMinimize, Mycell color, int depth, Board board, out int move, out int score) { if (0 == depth) { move = -1; score = ScoreBoard(board); } else { int bestScore=maximizeOrMinimize?-10000000:10000000; int bestMove=-1; for (int column=0; column<width; column++) { if (board._slots[0][column]!=Mycell.Barren) continue; int rowFilled = dropDisk(board, column, color); if (rowFilled == -1) continue; int s = ScoreBoard(board); if (s == (maximizeOrMinimize?orangeWins:yellowWins)) { bestMove = column; bestScore = s; board._slots[rowFilled][column] = Mycell.Barren; break; } int moveInner, scoreInner; abMinimax(!maximizeOrMinimize, color==Mycell.Orange?Mycell.Yellow:Mycell.Orange, depth-1, board, out moveInner, out scoreInner); board._slots[rowFilled][column] = Mycell.Barren; if (depth == maxDepth && g_debug) Console.WriteLine("Depth {0}, placing on {1}, score:{2}", depth, column, scoreInner); if (maximizeOrMinimize) { if (scoreInner>=bestScore) { bestScore = scoreInner; bestMove = column; } } else { if (scoreInner<=bestScore) { bestScore = scoreInner; bestMove = column; } } } move = bestMove; score = bestScore; } }
public static void abMinimax(bool maximizeOrMinimize, Mycell color, int depth, Board board, out int move, out int score) { if (0 == depth) { move = -1; score = ScoreBoard(board); } else { int bestScore = maximizeOrMinimize?-10000000:10000000; int bestMove = -1; for (int column = 0; column < width; column++) { if (board._slots[width * (0) + column] != Mycell.Barren) { continue; } int rowFilled = dropDisk(board, column, color); if (rowFilled == -1) { continue; } int s = ScoreBoard(board); if (s == (maximizeOrMinimize?orangeWins:yellowWins)) { bestMove = column; bestScore = s; board._slots[width * (rowFilled) + column] = Mycell.Barren; break; } int moveInner, scoreInner; if (depth > 1) { abMinimax(!maximizeOrMinimize, color == Mycell.Orange?Mycell.Yellow:Mycell.Orange, depth - 1, board, out moveInner, out scoreInner); } else { moveInner = -1; scoreInner = s; } board._slots[width * (rowFilled) + column] = Mycell.Barren; /* when loss is certain, avoid forfeiting the match, by shifting scores by depth... */ if (scoreInner == orangeWins || scoreInner == yellowWins) { scoreInner -= depth * (int)color; } if (depth == maxDepth && g_debug) { Console.WriteLine("Depth {0}, placing on {1}, score:{2}", depth, column, scoreInner); } if (maximizeOrMinimize) { if (scoreInner >= bestScore) { bestScore = scoreInner; bestMove = column; } } else { if (scoreInner <= bestScore) { bestScore = scoreInner; bestMove = column; } } } move = bestMove; score = bestScore; } }