public int tryToPlace(Point pt, bool isBlack) { toFlip.Clear(); toHint.ForEach(unhint); toHint.Clear(); Space toPlace = board.tryToPlace(pt, isBlack); if (toPlace == null) { return(-1); } int score = findFlips(toPlace, false); if (score == -1) { return(-1); } if (toPlace.status == 3 || toPlace.status == -3) { toPlace.confirmHint(isBlack); toPlace.highLight(); toFlip.ForEach(highlight); System.Threading.Thread.Sleep(10000); } if (!Form1.hintOn) { toPlace.placeDisc(isBlack); } // toHint.Remove(toPlace); // toHint.ForEach(unhint); if (isBlack) { blackPlayer.decCount(); blackStack.drawStack(blackPlayer.discsLeft); blackPlayer.raiseScore(score + 1); whitePlayer.lowerScore(score); } else { whitePlayer.decCount(); whiteStack.drawStack(whitePlayer.discsLeft); whitePlayer.raiseScore(score + 1); blackPlayer.lowerScore(score); } return(score); }
public int stringToBoard(String fileName, Player blackP, Player whiteP) { try { if (fileName == null) { MessageBox.Show("You must select an input file first. Use 'Image>Load'"); return -1; } string[] lines = System.IO.File.ReadAllLines(@fileName); char[] delims = { ' ', '\n' }; string[] firstLine = lines[0].Split(delims); clearBoard(); blackP.setScore(0); whiteP.setScore(0); blackP.discsLeft = 40; whiteP.discsLeft = 40; int piecesPlaced = 0; for (int r = 0; r < 8; r++) { string[] nextLine = lines[r].Split(delims); for (int c = 0; c < 8; c++) { int stat = Convert.ToInt32(nextLine[c]); Space newSpace = new Space(r, c, width, height, pG); board[r, c] = newSpace; if (stat == 1) { newSpace.placeDisc(true); blackP.raiseScore(1); piecesPlaced = piecesPlaced+1; } else if (stat == -1) { newSpace.placeDisc(false); whiteP.raiseScore(1); piecesPlaced = piecesPlaced + 1; } newSpace.status = stat; } } blackP.discsLeft = 40 - (piecesPlaced / 2); whiteP.discsLeft = 40 - (piecesPlaced / 2); } catch (Exception e) { MessageBox.Show(e.ToString()); } return 0; }