예제 #1
0
        private void RedoLastUndo()
        {
            if (m_CurSwapIndex < m_NumSwapsInGame)
            {
                //Debug.Assert(m_NumActionsInGame >= 0);
                int NumRedone = 0;

                while (m_CurSwapIndex <= m_NumSwapsInGame &&
                       m_SwapHistory[m_CurSwapIndex].m_MoveIndex == m_NumActionsInGame)
                {
                    NumRedone++;
                    CMove CurMove = m_SwapHistory[m_CurSwapIndex];
                    //Debug.Assert(m_CurSwapIndex < m_NumSwapsInGame);
                    SwapCards(m_CardLayout[CurMove.m_x2, CurMove.m_y2], m_CardLayout[CurMove.m_x1, CurMove.m_y1]);
                    m_CurSwapIndex++;
                }

                if (NumRedone > 1)
                {
                    m_NumShuffles++;
                }

                m_NumActionsInGame++;
            }
        }
예제 #2
0
        public void UndoLastMove()
        {
            if (m_WaitingForKing)
            {
                m_WaitingForKing = false;
                return;
            }

            if (m_CurSwapIndex > 0)
            {
                //Debug.Assert(m_NumActionsInGame > 0);
                //Debug.Assert(m_CurSwapIndex <= m_NumSwapsInGame);
                int NumBackuped = 0;

                while (m_CurSwapIndex > 0 && m_SwapHistory[m_CurSwapIndex - 1].m_MoveIndex == m_NumActionsInGame - 1)
                {
                    NumBackuped++;
                    CMove CurMove = m_SwapHistory[m_CurSwapIndex - 1];
                    //Debug.Assert(m_CurSwapIndex > 0);
                    SwapCards(m_CardLayout[CurMove.m_x2, CurMove.m_y2], m_CardLayout[CurMove.m_x1, CurMove.m_y1]);
                    m_CurSwapIndex--;
                }

                if (NumBackuped > 1)
                {
                    m_NumShuffles--;
                }

                m_NumActionsInGame--;
            }
        }
예제 #3
0
 public void SwapCards(CMove Move)
 {
     SwapCards(m_CardLayout[Move.m_x1, Move.m_y1], m_CardLayout[Move.m_x2, Move.m_y2]);
     if (m_CurSwapIndex < (int)Undos.MAX_UNDOS)
     {
         m_SwapHistory[m_CurSwapIndex++] = Move;
     }
     m_NumSwapsInGame = m_CurSwapIndex;
 }
예제 #4
0
        public bool MoveCard(int SlotX, int SlotY)
        {
            CCard CurCard = GetCard(SlotX, SlotY);

            if (m_WaitingForKing)
            {
                if (CurCard.GetValue() == 13)
                {
                    CMove Move = new CMove(0, m_WaitingKingY, SlotX, SlotY, m_NumActionsInGame++);
                    SwapCards(Move);
                    m_WaitingForKing = false;
                    return(true);
                }
            }
            else
            {
                // make sure we clicked on a hole
                if (CurCard.GetValue() == 1)
                {
                    // figure out what card we want to put here
                    if (SlotX == 0)
                    {
                        // we clicked on a king only slot
                        m_WaitingForKing = true;
                        m_WaitingKingY   = SlotY;
                        return(true);
                    }
                    else
                    {
                        CCard CardToLeft = GetCard(SlotX - 1, SlotY);
                        if (CardToLeft.GetValue() < 3)
                        {
                            return(false);
                        }
                        // find the card that we want to put here
                        for (int Y = 0; Y < (int)BoardSize.HEIGHT; Y++)
                        {
                            for (int X = 0; X < (int)BoardSize.WIDTH; X++)
                            {
                                CCard CheckCard = GetCard(X, Y);
                                if (CheckCard.GetSuit() == CardToLeft.GetSuit() &&
                                    CheckCard.GetValue() == CardToLeft.GetValue() - 1)
                                {
                                    CMove Move = new CMove(X, Y, SlotX, SlotY, m_NumActionsInGame++);
                                    SwapCards(Move);
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            return(false);
        }
예제 #5
0
        public void Shuffle()
        {
            if (m_WaitingForKing)
            {
                m_WaitingForKing = false;
            }

            m_NumShuffles++;

            for (int Y = 0; Y < (int)BoardSize.HEIGHT; Y++)
            {
                for (int X = 0; X < (int)BoardSize.WIDTH; X++)
                {
                    if (!CardIsInOrder(X, Y))
                    {
                        int Tries  = 0;
                        int OtherX = (int)Rand.Next((int)BoardSize.WIDTH);
                        int OtherY = (int)Rand.Next((int)BoardSize.HEIGHT);
                        while (CardIsInOrder(OtherX, OtherY) && Tries++ < 100000)
                        {
                            OtherX = (int)Rand.Next((int)BoardSize.WIDTH);
                            OtherY = (int)Rand.Next((int)BoardSize.HEIGHT);
                        }

                        CMove Move = new CMove(X, Y, OtherX, OtherY, m_NumActionsInGame);
                        SwapCards(Move);
                    }
                }
            }

            m_NumActionsInGame++;

            if (!MoveAvailable() && !IsSolved())
            {
                int expectedNumShuffles = m_NumShuffles;
                // if you shuffle results in no move available, undo the shuffel and try again.  Rand should change and we will get a new shuffle
                UndoLastMove();
                Shuffle();
                m_NumShuffles = expectedNumShuffles;
            }
        }
예제 #6
0
		public void SwapCards(CMove Move)
		{
			SwapCards(m_CardLayout[Move.m_x1, Move.m_y1], m_CardLayout[Move.m_x2, Move.m_y2]);
			if (m_CurSwapIndex < (int)Undos.MAX_UNDOS)
			{
				m_SwapHistory[m_CurSwapIndex++] = Move;
			}
			m_NumSwapsInGame = m_CurSwapIndex;
		}
예제 #7
0
		public void Shuffle()
		{
			if (m_WaitingForKing)
			{
				m_WaitingForKing = false;
			}

			m_NumShuffles++;

			for (int Y = 0; Y < (int)BoardSize.HEIGHT; Y++)
			{
				for (int X = 0; X < (int)BoardSize.WIDTH; X++)
				{
					if (!CardIsInOrder(X, Y))
					{
						int Tries = 0;
						int OtherX = (int)Rand.Next((int)BoardSize.WIDTH);
						int OtherY = (int)Rand.Next((int)BoardSize.HEIGHT);
						while (CardIsInOrder(OtherX, OtherY) && Tries++ < 100000)
						{
							OtherX = (int)Rand.Next((int)BoardSize.WIDTH);
							OtherY = (int)Rand.Next((int)BoardSize.HEIGHT);
						}

						CMove Move = new CMove(X, Y, OtherX, OtherY, m_NumActionsInGame);
						SwapCards(Move);
					}
				}
			}

			m_NumActionsInGame++;

			if (!MoveAvailable() && !IsSolved())
			{
				int expectedNumShuffles = m_NumShuffles;
				// if you shuffle results in no move available, undo the shuffel and try again.  Rand should change and we will get a new shuffle
				UndoLastMove();
				Shuffle();
				m_NumShuffles = expectedNumShuffles;
			}
		}
예제 #8
0
		public bool MoveCard(int SlotX, int SlotY)
		{
			CCard CurCard = GetCard(SlotX, SlotY);

			if (m_WaitingForKing)
			{
				if (CurCard.GetValue() == 13)
				{
					CMove Move = new CMove(0, m_WaitingKingY, SlotX, SlotY, m_NumActionsInGame++);
					SwapCards(Move);
					m_WaitingForKing = false;
					return true;
				}
			}
			else
			{
				// make sure we clicked on a hole
				if (CurCard.GetValue() == 1)
				{
					// figure out what card we want to put here
					if (SlotX == 0)
					{
						// we clicked on a king only slot
						m_WaitingForKing = true;
						m_WaitingKingY = SlotY;
						return true;
					}
					else
					{
						CCard CardToLeft = GetCard(SlotX - 1, SlotY);
						if (CardToLeft.GetValue() < 3)
						{
							return false;
						}
						// find the card that we want to put here
						for (int Y = 0; Y < (int)BoardSize.HEIGHT; Y++)
						{
							for (int X = 0; X < (int)BoardSize.WIDTH; X++)
							{
								CCard CheckCard = GetCard(X, Y);
								if (CheckCard.GetSuit() == CardToLeft.GetSuit()
									&& CheckCard.GetValue() == CardToLeft.GetValue() - 1)
								{
									CMove Move = new CMove(X, Y, SlotX, SlotY, m_NumActionsInGame++);
									SwapCards(Move);
									return true;
								}
							}
						}
					}
				}
			}

			return false;
		}