Beispiel #1
0
        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;
            }
        }
Beispiel #2
0
 //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);
 }
Beispiel #3
0
        public void UpdateAccessibility(PointI curr)
        {
            List <BoardPosition> PossiblePos = GetPossibleMovePositions(curr);

            foreach (BoardPosition p in PossiblePos)
            {
                p.PossibleMovesCount--;
            }
        }
Beispiel #4
0
        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));
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
 //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();
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
                }
            }
        }
Beispiel #10
0
        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]);
        }
Beispiel #11
0
 public BoardPosition GetPos(PointI c)
 {
     return(GetPos(c.x, c.y));
 }
Beispiel #12
0
 public int GetPossibleMovesCount(PointI curr)
 {
     return(m_logicsBoard.GetPossibleMoves(curr).Count);
 }
Beispiel #13
0
 public int GetIndex(PointI c)
 {
     return(m_logicsBoard.GetPos(c).MoveIndex);
 }
Beispiel #14
0
 public void SetIndex(PointI c, int index)
 {
     m_logicsBoard.GetPos(c).MoveIndex = index;
 }
Beispiel #15
0
 //check if the next position is valid and if it is occupied
 public bool IsNextPosValid(PointI next)
 {
     return(IsPosValid(next) == true && GetPos(next).IsUnoccupied());
 }