public MarkBot(int p, int t, int pos, SpookyMarkBot sm) { player = p; turn = t; position = pos; this.sm = sm; }
public SpookyMarkBot addSpookyMark() { MarkBot mark1 = currentSpookyMark[0]; MarkBot mark2 = currentSpookyMark[1]; currentSpookyMark = new List<MarkBot>(); SpookyMarkBot s = new SpookyMarkBot(mark1, mark2); mark1.sm = s; mark2.sm = s; spookyMarks.Add(s); if (entGraph.addEdgeSQ(squares[mark1.position], squares[mark2.position])) { toCollapse = s; return s; } HashSet<SquareBot> sqCycle = entGraph.getCycleSQ(squares[mark1.position]); if (sqCycle != null) { toCollapse = s; return s; } else { return null; } }
public void collapseHelper(int position, int player, int turn) { if (collapsed.Contains(position)) { return; } SquareBot square = squares[position]; square.setBigMark(player, turn); collapsed.Add(position); // Check all marks in the square S collapsed into. Each corresponding // SpookyMark collapses into the square S' that is NOT S. Then, recursively // check each of those squares S'. foreach (MarkBot mark in square.getMarks()) { SpookyMarkBot sm = mark.sm; int spookyPosition; if (sm.position1 == position) { spookyPosition = sm.position2; } else { spookyPosition = sm.position1; } collapseHelper(spookyPosition, sm.player, sm.turn); } }
private List <Action> getLegalActions(BoardBot board, int actionType, int agent, int turnNum) { // Generate all possible actions List <Action> result = new List <Action>(); if (actionType == 1) { // return the two possible squares we can collapse into. SpookyMarkBot sm = board.toCollapse; if (sm == null) { //log error Debug.Log("ERROR: Illegal action requested from bot."); return(null); } int pos1 = sm.position1; int pos2 = sm.position2; Debug.Log("Will collapse position: " + board.squares[pos1].position); result.Add(new Action(board.squares[pos1])); result.Add(new Action(board.squares[pos2])); return(result); } // Otherwise we return all the possible spookyMarks to add // First find all possible squares we can put marks on. List <int> validSquares = new List <int>(); for (int i = 0; i < 9; i++) { SquareBot sq = board.squares[i]; if (!sq.classicallyMarked && sq.filledMarks < 8) { validSquares.Add(i); } } // If no valid squares, return null if (validSquares.Count == 0) { return(null); } // If only one valid square, duplicate it so combinations(2, count) doesn't freak out if (validSquares.Count == 1) { validSquares.Add(validSquares[0]); } foreach (int first in validSquares) { foreach (int second in validSquares) { if (second <= first) { continue; } result.Add(new Action(first, second)); } } return(result); }
public SpookyMarkBot(SpookyMarkBot sm) { MarkBot mark1 = new MarkBot(sm.mark1); mark1.sm = this; MarkBot mark2 = new MarkBot(sm.mark2); mark2.sm = this; this.init(mark1, mark2); }
// Start is called before the first frame update public void init(GraphBot entGraph, SquareBot[] squares, List<SpookyMarkBot> spookyMarks, List<int> collapsed, SpookyMarkBot toCollapse, List<MarkBot> currentSpookyMark, int nextAction) { this.entGraph = entGraph; this.squares = squares; this.spookyMarks = spookyMarks; this.collapsed = collapsed; this.toCollapse = toCollapse; this.currentSpookyMark = currentSpookyMark; this.nextAction = nextAction; }
public void collapse(int mark) { int position = 0; if (mark == 1) { position = toCollapse.position1; } else if (mark == 2) { position = toCollapse.position2; } int player = toCollapse.player; int turn = toCollapse.turn; toCollapse = null; collapseHelper(position, player, turn); checkWin(); }
public void performAction(BoardBot board) { if (actionType == 0) { board.squares[p1].addMark(); board.squares[p2].addMark(); } else if (actionType == 1) { SpookyMarkBot toCollapse = board.toCollapse; int positionToCollapse = sqBot.position; if (positionToCollapse == toCollapse.position1) { board.collapse(1); } else if (positionToCollapse == toCollapse.position2) { board.collapse(2); } } }
public void nextTurn() { int lastPlayer = currentPlayer; int lastTurn = turnNum; if (currentPlayer == 1) { currentPlayer = 2; } else if (currentPlayer == 2) { currentPlayer = 1; } turnNum++; foreach (SquareBot square in board.squares) { square.reset(); } SpookyMarkBot s = board.addSpookyMark(); numMarks = 0; }
public override bool Equals(object obj) { SpookyMarkBot sm = (SpookyMarkBot)obj; return(player == sm.player && turn == sm.turn && position1 == sm.position1 && position2 == sm.position2); }