public Player(string p_name, Board.e_cell p_color) { this.name = p_name; this.color = p_color; this.changeTurn += (object s, Board b) => { }; }
private bool isWinningMove(int x, int y, Board.e_cell color) { foreach (t_Pattern pattern in _winPatterns) { List <t_vecPattern> winningPatterns = checkPatternInEveryDirection(x, y, pattern, color); foreach (t_vecPattern winPat in winningPatterns) { if (checkBreakableFive == false) { return(true); } List <t_vecPattern> breakers = new List <t_vecPattern>(); for (int i = 0; i < winPat.Second.First.Length; i++) { foreach (t_Pattern pat in _breakPatterns) { breakers.AddRange(checkPatternInEveryDirection(x + winPat.Second.First[i] * (int)winPat.First.x, y + winPat.Second.First[i] * (int)winPat.First.y, pat, color)); } } if (breakers.Count == 0) { return(true); } } } return(false); }
private bool isDoubleThree(int x, int y, Board.e_cell color) { List <t_vecPattern> directionsList = new List <t_vecPattern>(); foreach (t_Pattern pattern in _freeThrees) { directionsList.AddRange(checkPatternInEveryDirection(x, y, pattern, color)); } if (directionsList.Count > 1) { return(true); } else if (directionsList.Count > 0) { for (int i = 0; i < directionsList[0].Second.First.Length; i++) { if (directionsList[0].Second.Second[i] == e_cellColor.Same) { foreach (t_Pattern pattern in _freeThrees) { directionsList.AddRange(checkPatternInEveryDirection(x + (int)directionsList[0].First.x * directionsList[0].Second.First[i], y + (int)directionsList[0].First.y * directionsList[0].Second.First[i], pattern, color)); } } } } if (directionsList.Count > 1) { return(true); } return(false); }
public IA(string p_name, Board.e_cell p_color) { this.name = p_name; this.color = p_color; changeTurn += playNextMove; for (int i = 0; i < 324; i++) { weights[i] = 2; } }
public int matchForDirection(Board p_board, Vector2 p_dir, Vector2 p_pos) { int match = 0; for (int i = 0; i < pattern.Length; i++) { if (!pattern[i]) { Vector2 a_pos = p_pos - p_dir * i; Board.e_cell color = Board.e_cell.None; bool isMatch = true; for (int j = 0; j < pattern.Length; j++) { if (a_pos.x < 0 || a_pos.x >= 18 || a_pos.y < 0 || a_pos.y >= 18) { isMatch = false; break; } if (pattern[j]) { color = color == Board.e_cell.None ? p_board[(int)a_pos.x, (int)a_pos.y] != Board.e_cell.Empty ? p_board[(int)a_pos.x, (int)a_pos.y] : color : color; isMatch = (p_board[(int)a_pos.x, (int)a_pos.y] == color); } else { isMatch = (p_board[(int)a_pos.x, (int)a_pos.y] == Board.e_cell.Empty); } if (!isMatch) { break; } a_pos += p_dir; } if (isMatch) { match += score; } } } return(match); }
private t_vecPattern checkPattern(int x, int y, t_Pattern pattern, Board.e_cell color, Vector2 direction) { bool isPattern = true; for (int i = 0; i < pattern.First.Length; i++) { Vector2 p = new Vector2(x + pattern.First[i] * (int)(direction.x), y + pattern.First[i] * (int)(direction.y)); if (p.x >= 0 && p.x < 18 && p.y >= 0 && p.y < 18) { isPattern &= (board[(int)(p.x), (int)(p.y)] == (pattern.Second[i] == e_cellColor.Same ? color : pattern.Second[i] == e_cellColor.Inverse ? color == Board.e_cell.Black ? Board.e_cell.White : Board.e_cell.Black : Board.e_cell.Empty)); } else { isPattern = false; } } return(isPattern == true ? new t_vecPattern(direction, pattern) : null); }
public int move(int x, int y, Board.e_cell color) { int returnValue = 0; board[x, y] = color; List <t_vecPattern> pair = checkPatternInEveryDirection(x, y, _pairPattern, color); foreach (t_vecPattern dir in pair) { board[x + (int)(dir.First.x) * _pairPattern.First[0], y + (int)(dir.First.y) * _pairPattern.First[0]] = Board.e_cell.Empty; board[x + (int)(dir.First.x) * _pairPattern.First[1], y + (int)(dir.First.y) * _pairPattern.First[1]] = Board.e_cell.Empty; returnValue += 2; } if (isWinningMove(x, y, color)) { returnValue = -1; } return(returnValue); }
public void SetColor(Board.e_cell newColor) { rend = gameObject.GetComponent <Renderer> (); switch (newColor) { case Board.e_cell.Black: rend.enabled = true; rend.material.color = Color.blue; break; case Board.e_cell.White: rend.enabled = true; rend.material.color = Color.red; break; case Board.e_cell.Empty: rend.enabled = false; break; } }
public BitArray getMask(Board.e_cell p_color) { return(p_color == e_cell.Black ? getBlackMask() : getWhiteMask()); }
private List <t_vecPattern> checkPatternInEveryDirection(int x, int y, t_Pattern pattern, Board.e_cell color) { List <t_vecPattern> directionsList = new List <t_vecPattern>(); foreach (Vector2 direction in directions) { t_vecPattern dir = checkPattern(x, y, pattern, color, direction); if (dir != null) { if (pattern != _freeThrees[1] || directionsList.Find((t_vecPattern vp) => { return(dir.First == (vp.First * -1)); }) == null) { directionsList.Add(dir); } } } return(directionsList); }