public void MoveNext() { if (b1stTime) { b1stTime = false; curr.x = currentX + 1; curr.y = currentY + 1; mainBoard.SetIndex(curr, 1); writexyC(curr, 1, true);//highlight color IsAlive = true; return; } int poss_num = mainBoard.GetPossibleMovesCount(curr); int boardindex = mainBoard.GetIndex(curr); if (poss_num != 0 && boardindex <= 64) { writexyC(curr, boardindex, false); //reset color mainBoard.UpdateAccessibility(curr); //update current position accessibility curr = mainBoard.DetermineNextMove(curr); mainBoard.SetIndex(curr, ++boardindex); writexyC(curr, boardindex, true);//highlight color if (boardindex == 64) { IsAlive = false; } } else { IsAlive = false; } }
//check if this position is valid or not public bool IsPosValid(PointI pos1) { if ((pos1.x < 1) || (pos1.y < 1) || (pos1.x > colCount) || (pos1.y > rowCount)) { return(false); } return(true); }
public void UpdateAccessibility(PointI curr) { List <BoardPosition> PossiblePos = GetPossibleMovePositions(curr); foreach (BoardPosition p in PossiblePos) { p.PossibleMovesCount--; } }
int GetSmallestAccessVal(PointI curr) { // Get all possible moves from a given position List <BoardPosition> Positions = GetPossibleMovePositions(curr); if (Positions == null || Positions.Count == 0) { return(-1); } return(GetSmallestAccessVal(Positions)); }
List <BoardPosition> GetPossibleMovePositions(PointI curr) { List <PointI> PossiblePoints = m_logicsBoard.GetPossibleMoves(curr); List <BoardPosition> PossiblePos = new List <BoardPosition>(); foreach (PointI p in PossiblePoints) { PossiblePos.Add(m_logicsBoard.GetPos(p)); } return(PossiblePos); }
//write number to the board w/ color void writexyC(PointI curr, int boardindex, bool bHighlight) { if (bHighlight) { cells[curr.x - 1, curr.y - 1].Fill = redBrush; } else { cells[curr.x - 1, curr.y - 1].Fill = yellowBrush; } texts[curr.x - 1, curr.y - 1].Text = boardindex.ToString(); }
public List <PointI> GetPossibleMoves(PointI curr) { PointI next; List <PointI> PossibleMoves = new List <PointI>(); for (int moveNumber = 0; moveNumber < MaxPossMoves; moveNumber++) { next = curr.GetNextMove(horizontal[moveNumber], vertical[moveNumber]); if (IsNextPosValid(next)) { PossibleMoves.Add(next); } } return(PossibleMoves); }
List <BoardPosition> GetSmallestAccessArray(PointI curr) { // Get all possible moves from a given position List <BoardPosition> Positions = GetPossibleMovePositions(curr); // Get the smallest value int smallestValue = GetSmallestAccessVal(Positions); // Remove non-smallest positions for (int i = 0; i < Positions.Count; i++) { if (Positions[i].PossibleMovesCount > smallestValue) { Positions.RemoveAt(i); i--; } } return(Positions); }
public void Init() { int i, j; for (i = 1; i <= rowCount; i++) { for (j = 1; j <= colCount; j++) { m_logicsBoard.GetPos(i, j).SetUnoccupied(); } } //initialize the m_possibleMovesMatrix array for (i = 1; i <= rowCount; i++) { for (j = 1; j <= colCount; j++) { PointI p = new PointI(i, j); m_logicsBoard.GetPos(i, j).PossibleMovesCount = GetPossibleMovesCount(p); } } }
public PointI DetermineNextMove(PointI curr) { // There can be multiple cells with the same lowest move count: up to 8 // get smallest possible move count array for level 1 List <BoardPosition> L1Candidates = GetSmallestAccessArray(curr); if (L1Candidates.Count == 0) { return(null); } if (L1Candidates.Count == 1) { return(L1Candidates[0]); } // level 2 forward check int smallestAccessValIndex_Level1 = 0; BoardPosition candidatePos = L1Candidates[smallestAccessValIndex_Level1]; int smallestAccessVal_Level1 = candidatePos.PossibleMovesCount; // designate 1st one is the smallest int smallestAccessVal_Level2 = GetSmallestAccessVal(candidatePos); int candidate_smallestAccessVal_Level2 = -1; for (int level1_i = 1; level1_i < L1Candidates.Count; level1_i++) { candidate_smallestAccessVal_Level2 = GetSmallestAccessVal(L1Candidates[level1_i]); // if the level 2 if (smallestAccessVal_Level2 > candidate_smallestAccessVal_Level2) { smallestAccessValIndex_Level1 = level1_i; } } return(L1Candidates[smallestAccessValIndex_Level1]); }
public BoardPosition GetPos(PointI c) { return(GetPos(c.x, c.y)); }
public int GetPossibleMovesCount(PointI curr) { return(m_logicsBoard.GetPossibleMoves(curr).Count); }
public int GetIndex(PointI c) { return(m_logicsBoard.GetPos(c).MoveIndex); }
public void SetIndex(PointI c, int index) { m_logicsBoard.GetPos(c).MoveIndex = index; }
//check if the next position is valid and if it is occupied public bool IsNextPosValid(PointI next) { return(IsPosValid(next) == true && GetPos(next).IsUnoccupied()); }