예제 #1
0
			public Action(PieceState pieceState, Intersection fromIntr, Intersection toIntr, ActionType actionType)
			{
				m_pieceState = pieceState;
				m_fromIntr = fromIntr;
				m_toIntr = toIntr;
				m_actionType = actionType;
			}
예제 #2
0
			public Action(PieceState pieceState, Square fromSqr, Square toSqr, ActionType actionType)
			{
				m_pieceState = pieceState;
				m_fromSqr = fromSqr;
				m_toSqr = toSqr;
				m_actionType = actionType;
			}
예제 #3
0
		// Move given Piece from Intersection to Intersection
		public void MovePiece(Piece piece, Intersection fromIntr, Intersection toIntr)
		{
			PieceState movedPiece = new PieceState(piece, fromIntr);
			if(m_pieces.Contains(movedPiece))
			{
				m_pieces.Find(item => item.Equals(movedPiece)).Intersection = toIntr;
			}
		}
예제 #4
0
		// Move given Piece from Square to Square
		public void MovePiece(Piece piece, Square fromSquare, Square toSquare)
		{
			PieceState movedPiece = new PieceState(piece, fromSquare);

			if(m_pieces.Contains(movedPiece))
			{
				m_pieces.Find(item => item.Equals(movedPiece)).Square = toSquare;
			}

		}
예제 #5
0
		// Remove piece on Intersection
		public void RemovePiece(Intersection intersection)
		{
			PieceState removedPiece = m_pieces.Find(item => item.Intersection == intersection);

			if (m_pieces.Contains(removedPiece)) 
			{
				removedPiece.IsActive = false;
				m_pieces.Remove(removedPiece);
			}
		}
예제 #6
0
		// Remove piece by Piece
		public void RemovePiece(Piece piece)
		{
			PieceState removedPiece = m_pieces.Find(x => x.Piece == piece);

			if(m_pieces.Contains(removedPiece))
			{
				removedPiece.IsActive = false;
				m_pieces.Remove(removedPiece);
			}
		}
예제 #7
0
		// Get PieceState by PieceState
		public PieceState GetPieceState(PieceState piece)
		{
			foreach(PieceState item in m_pieces)
			{
				if(item == piece)
					return item;
			}

			Debug.WriteLine("GetPieceState(PieceState) : PieceState {0} does not exist in List<PieceState> m_pieces.", piece);

			return null;
		}
예제 #8
0
		// Swap piece1 with piece2 on the board
		public void SwapPiece(Piece piece1, Piece piece2)
		{
			PieceState pieceState1 = GetPieceState(piece1);
			PieceState pieceState2 = GetPieceState(piece2);
			PieceState _bufferPiece = pieceState2;
		
			// pieceState2 = pieceState1
			pieceState2.Square = pieceState1.Square;

			// pieceState1 = pieceState2
			pieceState1.Square = _bufferPiece.Square;

		}
예제 #9
0
		// Swap piece1 with piece2, in case square is choosen by player (Tetraglobe swap)
		public void SwapPiece(Piece piece1, Piece piece2, Square toSqr, Intersection toIntr)
		{
			if(piece2.Type != PieceType.Tetraglobe)
			{
				SwapPiece(piece1, piece2);
			}
			else
			{
				PieceState pieceState1 = GetPieceState(piece1);
				PieceState pieceState2 = GetPieceState(piece2);

				// pieceState2 = pieceState1
				pieceState2.Square = toSqr;

				// pieceState1 = pieceState2
				pieceState1.Intersection = toIntr;

			}
		}
예제 #10
0
		// Transforms a given piece to another
		public void TransformPiece(PieceType type, Intersection toIntr, Square toSqr, params Piece[] piece)
		{
			PieceState pBuffer = GetPieceState(piece[piece.Length-1]);

			// If we're not transforming Globules to some other piece
			if(piece[0].Type != PieceType.Globule && type == PieceType.Globule && piece.Length == 1)
			{
				m_pieces[m_pieces.IndexOf(pBuffer)] = new PieceState(new Piece(type, piece[0].Color), pBuffer.Square);
			}

			// Transforming one Piece to a given Square
			else if(piece.Length == 1 && toSqr != null)
			{
				if(toSqr.X <= 7 && toSqr.X >= 0 && toSqr.Y <= 7 && toSqr.Y >= 0)
					m_pieces[m_pieces.IndexOf(pBuffer)] = new PieceState(new Piece(type, piece[0].Color), toSqr);
			}

			// Changing multiple Globules to a Tetraglobe
			else if(piece.Length > 1 && toIntr != null)
			{
				List<PieceState> pieceList = new List<PieceState>();

				// Getting all PieceStates of our given Pieces
				foreach(Piece item in piece)
				{
					pieceList.Add(GetPieceState(item));
				}

				// Removing from the playing pieces list all pieces, EXCEPT THE LAST ONE
				for(int i = 0; i < pieceList.Count-1; i++)
				{
					m_pieces.Remove(pieceList[i]);
				}

				if(type != PieceType.Tetraglobe)
					m_pieces[m_pieces.IndexOf(pBuffer)] = new PieceState(new Piece(type, piece[0].Color), toSqr);

				else if(type == PieceType.Tetraglobe && toIntr.A <= 7 && toIntr.A >= 0 && toIntr.B <= 7 && toIntr.B >= 0)
					m_pieces[m_pieces.IndexOf(pBuffer)] = new PieceState(new Piece(type, piece[0].Color), toIntr);
			}
		}
예제 #11
0
		// Returns a list of possible actions for a given piece
		public List<ActionType> GetPossibleActions(Piece piece, bool power = false)
		{
			PieceState pieceState = m_board.GetPieceState(piece);

			List<ActionType> actionList = new List<ActionType>();
			List<Square> sqrAround = new List<Square>();
			List<Intersection> intrAround = new List<Intersection>();

			bool nextToEnemy = false;

			// If the move is a free move, possibility to skip it
			if(pieceState.HasFreeMove)
				actionList.Add(ActionType.SkipTurn);
			
			if(pieceState.Piece.Type != PieceType.Astree)
				actionList.Add(ActionType.DeleteThis);

			// Return possible actions for a given Globule
			if(pieceState.Piece.Type == PieceType.Globule)
			{
				sqrAround.Clear();

				// First checking if any Square around is free
				sqrAround = m_board.GetFreeSquares(pieceState.Square);
				
				if(CanTransform(pieceState.Piece))
					actionList.Add(ActionType.Transform);
				
				if(!sqrAround.Any()) // If sqrAround is NOT empty - Meaning there's free Square(s) around
					actionList.Add(ActionType.Create); // Add the creating action to the possible actions list
				
				// If the piece is powerful and last action has been made by an enemy
				if(power && m_actionStack.Peek().PieceState.Piece.Color != pieceState.Piece.Color)
				{
					// Giving all allied (and this one) Globules a free move, letting the player chose which one he'll play 
					foreach(PieceState pState in m_board.Pieces)
					{
						// All free moves & all will probably be handeled in live by the presenter
						
						if(pState.Piece.Type == PieceType.Globule)
							pState.HasFreeMove = true;
					}
				}
			} // endof Globule

			else if(pieceState.Piece.Type == PieceType.Triglobe || pieceState.Piece.Type == PieceType.Triastre)
			{
				sqrAround.Clear();

				sqrAround = Square.GetSquaresAround(pieceState.Square);

				foreach(Square sqr in sqrAround)
					if(m_board.GetPieceState(sqr).Piece.Color != pieceState.Piece.Color)
						nextToEnemy = true;

				if(sqrAround.Count != 0) // If there's free Squares around
					actionList.Add(ActionType.Move);
				if(nextToEnemy && !actionList.Contains(ActionType.Move))
					actionList.Add(ActionType.Move);
			} // endof Triglobe || Triastre

			else if(pieceState.Piece.Type == PieceType.Tetraglobe)
			{
				intrAround.Clear();

				intrAround = Intersection.GetIntersectionsAround(pieceState.Intersection);

				List<Square> _buffPossibleSqrList = new List<Square>();

				List<Square> _buffSqrList;
				PieceState _bufferPiece; 
				PieceState _buffNextPiece;

				int currentIndex;

				foreach(Intersection item in intrAround)
				{
					_buffSqrList = Square.GetByIntersection(item);
					_bufferPiece = m_board.GetPieceState(item);

					if (_bufferPiece.Piece.Type == PieceType.Tetraglobe && _bufferPiece.Piece.Color != pieceState.Piece.Color)
					{
						actionList.Add(ActionType.Move);
						break;
					}

					foreach(Square sqrItem in _buffSqrList)
					{
						_bufferPiece = m_board.GetPieceState(sqrItem);

						if(_bufferPiece != pieceState && _bufferPiece.Piece.Color != pieceState.Piece.Color
						|| _bufferPiece == null)
						_buffPossibleSqrList.Add(sqrItem);
					}

					foreach(Square sqrItem in _buffPossibleSqrList)
					{
						_bufferPiece = m_board.GetPieceState(sqrItem);
						currentIndex = m_board.Pieces.IndexOf(_bufferPiece);

						for(int i = 0; i < _buffPossibleSqrList.Count; i++)
						{
							if(_buffPossibleSqrList[i] == sqrItem)
								break;

							_buffNextPiece = m_board.Pieces[currentIndex+i];

							if (_buffNextPiece.Square.X == _bufferPiece.Square.X + 1)
							{
								actionList.Add(ActionType.Move);
								break;
							}

							if (_buffNextPiece.Square.X == _bufferPiece.Square.X - 1)
							{
								actionList.Add(ActionType.Move);
								break;
							}

							if (_buffNextPiece.Square.Y == _bufferPiece.Square.Y + 1)
							{
								actionList.Add(ActionType.Move);
								break;
							}

							if (_buffNextPiece.Square.Y == _bufferPiece.Square.Y - 1)
							{
								actionList.Add(ActionType.Move);
								break;
							}

							
						}

						if (_bufferPiece == null) // If the Square is empty
						{
							actionList.Add(ActionType.Move);
							break;
						}
						if(_bufferPiece.Piece.Color != pieceState.Piece.Color)
							actionList.Add(ActionType.Move);
					}
				}
			} // endof Tetraglobe

			else if(pieceState.Piece.Type == PieceType.Tetrastre)
			{
				sqrAround.Clear();

				sqrAround = Square.GetSquaresAround(pieceState.Square, true);

				PieceState _bufferPiece;

				foreach(Square item in sqrAround)
				{
					// First, we change the range, since the Tetrastre moves by EVEN numbers of squares ;)
					item.X+=1;
					item.Y+=1;

					_bufferPiece = m_board.GetPieceState(item);

					if(!m_board.Pieces.Contains(_bufferPiece)) // If that Square IS EMPTY
					{
						actionList.Add(ActionType.Move);
					}
				}
			} // endof Tetrastre

			else if(pieceState.Piece.Type == PieceType.Pentaglobe)
			{
				if(power)
				{
					Action _actionBuff = m_actionStack.Peek();

					// If the Pentaglobe is powerful and has just swapped position with an allied Globule
					if(_actionBuff.PieceState == pieceState && _actionBuff.TargetState.Piece.Type == PieceType.Globule
					   && _actionBuff.TargetState.Piece.Color == pieceState.Piece.Color)
						actionList.Add(ActionType.DeleteLastSwapped);
				}
				
				if (m_board.Pieces.Any(item => item.Piece.Type != PieceType.Pentaglobe && item.Piece.Color == pieceState.Piece.Color))
				{
					actionList.Add(ActionType.Swap);
				}

			} // endof Pentaglobe

			else if(pieceState.Piece.Type == PieceType.Pentastre)
			{
				sqrAround.Clear();

				sqrAround = Square.GetSquaresAround(pieceState.Square, true);

				PieceState _bufferPiece;

				foreach(Square item in sqrAround)
				{
					_bufferPiece = m_board.GetPieceState(item);

					// If a Square next to us is EMPTY - OR - if we're powerful and that Square is occupied by an enemy Pentastre
					if(_bufferPiece == null
					|| power && _bufferPiece.Piece.Type == PieceType.Pentastre && _bufferPiece.Piece.Color != pieceState.Piece.Color)
					{
						actionList.Add(ActionType.Move);
					}
				}
			} // endof Pentastre

			else if(pieceState.Piece.Type == PieceType.Rosace)
			{
				sqrAround.Clear();

				// ReSharper disable once ArgumentsStyleLiteral
				sqrAround = Square.GetSquaresAround(pieceState.Square, diagonal:true);
			
				List<Square> _sqrToRemove = new List<Square>();

				PieceState _bufferPiece;
				Square actualSqr = pieceState.Square;

				// First, removing all "illegal-to-move-on" Squares
				foreach(Square item in sqrAround)
				{
					// Since the Rosace can only move diagonally, we're removing the ortogonal Squares
					if(item.X == actualSqr.X+1 && item.Y == actualSqr.Y // right
					|| item.X == actualSqr.X-1 && item.Y == actualSqr.Y // left
					|| item.X == actualSqr.X && item.Y == actualSqr.Y+1 // top
					|| item.X == actualSqr.X && item.Y == actualSqr.Y-1) // down
						_sqrToRemove.Add(item);

				}

				// Now, checking the "legal-to-move-on" Squares
				foreach(Square item in sqrAround)
				{
					_bufferPiece = m_board.GetPieceState(item);

					if(_bufferPiece == null)
					{
						actionList.Add(ActionType.Move);
					}
				}
			} // endof Rosace

			else if(pieceState.Piece.Type == PieceType.Astree)
			{
				sqrAround.Clear();

				sqrAround = Square.GetSquaresAround(pieceState.Square, true);
				List<Square> sqrAroundAround = sqrAround; // SqrAround with +1 range !

				PieceState _bufferPiece;
				Square _bufferSquare = new Square();

				// Setting the correct range for SqrAroundAround
				foreach(Square sqrItem in sqrAroundAround)
				{
					sqrItem.X+=1;
					sqrItem.Y+=1;

					_bufferPiece = m_board.GetPieceState(sqrItem);

					if(_bufferPiece != null && _bufferPiece.Piece.Color == pieceState.Piece.Color) // If the Square CONTAINS an ALLY, we CANNOT GO there,
					{
						sqrAroundAround.Remove(_bufferPiece.Square);
					}
				}

				// Checking Squares directly next to 'pieceState'
				foreach(Square nxtSqrItem in sqrAround)
				{

					_bufferPiece = m_board.GetPieceState(nxtSqrItem);

					if(m_board.Pieces.Contains(_bufferPiece)) // If there's a piece next to us
					{
						// Left
						if(nxtSqrItem.X == pieceState.Square.X-1)		
						{
							_bufferSquare.X = nxtSqrItem.X-1; // Going left
							_bufferSquare.Y = nxtSqrItem.Y;

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare))
							{
								actionList.Add(ActionType.Move);
							}
						}
						
						// Right
						else if(nxtSqrItem.X == pieceState.Square.X+1)		
						{
							_bufferSquare.X = nxtSqrItem.X+1; // Going right
							_bufferSquare.Y = nxtSqrItem.Y;

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
							}
						}

						// Top
						else if(nxtSqrItem.Y == pieceState.Square.Y+1)		
						{
							_bufferSquare.X = nxtSqrItem.X;
							_bufferSquare.Y = nxtSqrItem.Y+1; // Going top

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
								break;
							}
						}

						// Down
						else if(nxtSqrItem.Y == pieceState.Square.Y-1)		
						{
							_bufferSquare.X = nxtSqrItem.X;
							_bufferSquare.Y = nxtSqrItem.Y-1; // Going down

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
								break;
							}
						}

						// Top-Left
						else if(nxtSqrItem.X == pieceState.Square.X-1 && nxtSqrItem.Y == pieceState.Square.Y+1)		
						{
							_bufferSquare.X = nxtSqrItem.X-1; // Going left
							_bufferSquare.Y = nxtSqrItem.Y+1; // Going top

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
								break;
							}
						}

						// Top-Right
						else if(nxtSqrItem.X == pieceState.Square.X+1 && nxtSqrItem.Y == pieceState.Square.Y+1)
						{
							_bufferSquare.X = nxtSqrItem.X+11; // Going right
							_bufferSquare.Y = nxtSqrItem.Y; // Going top

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
							}
						}
						
						// Down-Left
						else if(nxtSqrItem.X == pieceState.Square.X-1 && nxtSqrItem.Y == pieceState.Square.Y-1)		
						{
							_bufferSquare.X = nxtSqrItem.X-1; // Going left
							_bufferSquare.Y = nxtSqrItem.Y; // Going down

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
							}
						}

						// Down-Right
						else if(nxtSqrItem.X == pieceState.Square.X+1)		
						{
							_bufferSquare.X = nxtSqrItem.X+1; // Going right
							_bufferSquare.Y = nxtSqrItem.Y; // Going down

							// If the Square is empty or contains an enemy, it is a legal move
							if(sqrAroundAround.Contains(_bufferSquare) && !actionList.Contains(ActionType.Move))
							{
								actionList.Add(ActionType.Move);
							}
						}
					}
				}	

				actionList.Add(ActionType.Create);
			} // endof Astree

			actionList.Reverse();
			return actionList;
		} // endof GetPossibleActions()
예제 #12
0
		} // endof CheckTriggers(Piece, Square)



		// FIXME: Stack action is part of the Action managing system (undo/redo)


		// StackAction is called once an action as been performed by the user
		// It is used to store the user's actions so he's able to keep track and undo those actions
		// 'pieceState' reprensents the piece PERFORMING the action
		public void StackAction(PieceState pieceState, Square fromSqr, Square toSqr, ActionType actionType)
		{
			m_actionStack.Push(new Action(pieceState, fromSqr, toSqr, actionType));
		}
예제 #13
0
		public void StackAction(PieceState pieceState, Intersection fromIntr, Intersection toIntr, ActionType actionType)
		{
			m_actionStack.Push(new Action(pieceState, fromIntr, toIntr, actionType));
		}
예제 #14
0
		public void StackAction(Piece piece, Square fromSqr, Square toSqr, ActionType actionType)
		{
			PieceState _bufferPiece = m_board.GetPieceState(piece);
			m_actionStack.Push(new Action(_bufferPiece, fromSqr, toSqr, actionType));
		}
예제 #15
0
		public void StackAction(Piece piece, Intersection fromIntr, Intersection toIntr, ActionType actionType)
		{
			PieceState _bufferPiece = m_board.GetPieceState(piece);
			m_actionStack.Push(new Action(_bufferPiece, fromIntr, toIntr, actionType));
		}
예제 #16
0
		} // endof GetPossibleActions()

		// Returns a list of legal squares for 'piece' to perform 'action' (For square highlighting purpose)
		public List<Square> GetLegalSquares(ActionType action, Piece piece, bool power = false)
		{
			List<Square> legalSquares = new List<Square>();
			
			// ReSharper disable once InconsistentNaming
			PieceState _bufferPiece = m_board.GetPieceState(piece);
			
			Square startSqr = _bufferPiece.Square;
			Intersection startIntr = _bufferPiece.Intersection;

			Square checkingSqr = startSqr;
			Intersection checkingIntr = startIntr;
			
			if (action == ActionType.Move)
			{
				// Testing UP
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y++;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B++;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}

				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing DOWN
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y--;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B--;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing RIGHT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.X++;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.A++;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing LEFT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.X--;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.A--;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing UP-RIGHT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y++;
						checkingSqr.X++;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B++;
						checkingIntr.A++;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing UP-LEFT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y++;
						checkingSqr.X--;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B++;
						checkingIntr.A--;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing DOWN-RIGHT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y--;
						checkingSqr.X++;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B--;
						checkingIntr.A++;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
				
				// Going back to our starting position
				checkingSqr = startSqr;
				checkingIntr = startIntr;
				
				// Testing DOWN-LEFT
				while (true)
				{
					if (piece.Type != PieceType.Tetraglobe)
					{
						checkingSqr.Y--;
						checkingSqr.X--;
						if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
							legalSquares.Add(checkingSqr);
						else
							break;
					}
					else
					{
						checkingIntr.B--;
						checkingIntr.A--;
						if (CheckMoveIsValid(piece, startIntr, checkingIntr, power))
							legalSquares.AddRange(checkingIntr.ToSquares);
						else
							break;
					}
				}
			}
			
			else if (action == ActionType.Create)
			{
				// Checking UP
				checkingSqr = startSqr;
				checkingSqr.Y++;
				if(CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);

				// Checking DOWN
				checkingSqr = startSqr;
				checkingSqr.Y--;
				if(CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking RIGHT
				checkingSqr = startSqr;
				checkingSqr.X++;
				if(CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking LEFT
				checkingSqr = startSqr;
				checkingSqr.X--;
				if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking UP-RIGHT
				checkingSqr = startSqr;
				checkingSqr.Y++;
				checkingSqr.X++;
				if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking UP-LEFT
				checkingSqr = startSqr;
				checkingSqr.Y++;
				checkingSqr.X--;
				if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking DOWN-RIGHT
				checkingSqr = startSqr;
				checkingSqr.Y--;
				checkingSqr.X++;
				if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
				
				// Checking DOWN-LEFT
				checkingSqr = startSqr;
				checkingSqr.Y--;
				checkingSqr.X--;
				if (CheckMoveIsValid(piece, startSqr, checkingSqr, power))
					legalSquares.Add(checkingSqr);
			}
			
			else if (action == ActionType.Transform)
			{	
				// Checking for another Globule UP
				checkingSqr = startSqr;
				checkingSqr.Y++;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule DOWN
				checkingSqr = startSqr;
				checkingSqr.Y--;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule RIGHT
				checkingSqr = startSqr;
				checkingSqr.X++;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule LEFT
				checkingSqr = startSqr;
				checkingSqr.X--;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule UP-RIGHT
				checkingSqr = startSqr;
				checkingSqr.Y++;
				checkingSqr.X++;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule UP-LEFT
				checkingSqr = startSqr;
				checkingSqr.Y++;
				checkingSqr.X--;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule DOWN-RIGHT
				checkingSqr = startSqr;
				checkingSqr.Y--;
				checkingSqr.X++;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
				
				// Checking for another Globule DOWN-LEFT
				checkingSqr = startSqr;
				checkingSqr.Y--;
				checkingSqr.X--;
				if (m_board.GetPieceOnSqr(checkingSqr) != null)
					legalSquares.Add(checkingSqr);
			}
			
			else if (action == ActionType.Swap)
			{
				// Returning all allies positions :)
				foreach (PieceState item in m_board.Pieces)
				{
					if (item.Piece.Color == piece.Color)
						if (item.Piece.Type != PieceType.Tetraglobe)
							legalSquares.Add(item.Square);
						else
							legalSquares.AddRange(item.Intersection.ToSquares);
				}
			}
			
			return legalSquares;
		}
예제 #17
0
		// Get Piece on Square -- returns null if empty
		public Piece GetPieceOnSqr(Square sqr)
		{
			PieceState _bufferPiece = m_pieces.Find(x => x.Square == sqr);
			return _bufferPiece.Piece;
		}
예제 #18
0
		// Returns a boolean value based on what is whithin the range of the desired transformation
		// 'wantedPieceType' is mostly used to get a valid return value for a transformation to Tetraglobe
		public bool CanTransform(Piece piece, PieceType wantedPieceType = PieceType.None)
		{
			if(piece.Type != PieceType.Globule)
				return false;

			PieceState pieceState = m_board.GetPieceState(piece);

			List<PieceState> pieceList = new List<PieceState>();
			List<Square> sqrAround = new List<Square>(); 
			Square pieceSquare = pieceState.Square;

			PieceState pBuffer = m_board.GetPieceState(piece);

			if(wantedPieceType == PieceType.Globule)
				return false;

			if(wantedPieceType == PieceType.None || wantedPieceType == PieceType.Triglobe
			|| wantedPieceType == PieceType.Triastre)
			{
				sqrAround = Square.GetSquaresAround(pieceSquare); // Get squares 

				for(int i = 0; i < pieceList.Count; i++)
				{
					pieceList.Add(m_board.GetPieceState(sqrAround[i]));

					// If there's at least one globule next to 'piece'
					if(pieceList[i].Piece.Type == PieceType.Globule && wantedPieceType == PieceType.None
					&& pieceList[i].Piece.Color == pBuffer.Piece.Color
					|| pieceList[i].Piece.Type == PieceType.Globule && wantedPieceType == PieceType.Triglobe
					&& pieceList[i].Piece.Color == pBuffer.Piece.Color
					|| pieceList[i].Piece.Type == PieceType.Globule && wantedPieceType == PieceType.Triastre
					&& pieceList[i].Piece.Color == pBuffer.Piece.Color)
						return true;
				}

			}
			
			else if(wantedPieceType != PieceType.None || wantedPieceType != PieceType.Triglobe
			|| wantedPieceType != PieceType.Triastre)
			{
				List<Intersection> intrAround = pieceSquare.IntersectionsAround;
				
				foreach(Intersection intrItem in intrAround)
				{
					sqrAround = intrItem.ToSquares;
					int globulesOnIntr = 0;

					for(int i = 0; i < sqrAround.Count; i++)
					{
						pieceList.Add(m_board.GetPieceState(sqrAround[i]));

						// We need minimum 4 Globules, somewhere, making a 2x2 square with 'piece'
						if(pBuffer.Piece.Type == PieceType.Globule && pieceList[i].Piece.Color == pBuffer.Piece.Color && pieceList.Count == 4)
							globulesOnIntr++;
					}

					if(globulesOnIntr == 4)
						return true;
				}

			}

			return false;
		}
예제 #19
0
		// Get Piece on Intersection -- returns null if empty
		public Piece GetPieceOnIntr(Intersection intr)
		{
			PieceState _bufferPiece = m_pieces.Find(x => x.Intersection == intr);

			return _bufferPiece.Piece;
		}
예제 #20
0
		// Checks if a given piece is powerful
		public bool CheckPower(Piece piece)
		{
			if (piece.Type == PieceType.Astree)
				return false;
			
			PieceState _bufferPiece = Board.GetPieceState(piece);
			bool power = false;
			
			// Each astree inverts the power of each pieces
			foreach (PieceState item in m_board.Pieces)
			{
				if (item.Piece.Type == PieceType.Astree)
					power = !power;
			}

			if (piece.Type != PieceType.Tetraglobe)
			{
				Square _bufferPos = _bufferPiece.Square;

				// Checking for Rosaces with no obstacles inbetween
				
				// RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;

					if (_bufferPos.X > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;

					if (_bufferPos.X < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// UP
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.Y++;

					if (_bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// DOWN
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.Y--;

					if (_bufferPos.X < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// UP-RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;
					_bufferPos.Y++;

					if (_bufferPos.X > 7 || _bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// UP-LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;
					_bufferPos.Y++;

					if (_bufferPos.X < 0 || _bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// DOWN-RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;
					_bufferPos.Y--;

					if (_bufferPos.X > 7 || _bufferPos.Y < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;

				// DOWN-LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;
					_bufferPos.Y--;

					if (_bufferPos.X < 0 || _bufferPos.Y < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
						power = !power;
				}

				
				// Checking for (powerful) Rosaces WITH obstacles inbetween				
				
				_bufferPos = _bufferPiece.Square;

				// RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;

					if (_bufferPos.X > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;

					if (_bufferPos.X < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// UP
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.Y++;

					if (_bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// DOWN
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.Y--;

					if (_bufferPos.X < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// UP-RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;
					_bufferPos.Y++;

					if (_bufferPos.X > 7 || _bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// UP-LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;
					_bufferPos.Y++;

					if (_bufferPos.X < 0 || _bufferPos.Y > 7)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// DOWN-RIGHT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X++;
					_bufferPos.Y--;

					if (_bufferPos.X > 7 || _bufferPos.Y < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}

				_bufferPos = _bufferPiece.Square;
				
				// DOWN-LEFT
				foreach (PieceState item in m_board.Pieces)
				{
					_bufferPos.X--;
					_bufferPos.Y--;

					if (_bufferPos.X < 0 || _bufferPos.Y < 0)
						break;

					if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
						power = !power;
				}
			}
			
			else if (piece.Type == PieceType.Tetraglobe)
			{
				Intersection _bufferIntr = _bufferPiece.Intersection;

				// Checking for Rosaces with no obstacles inbetween
				for (int i = 0; i < _bufferIntr.ToSquares.Count; i++)
				{
					Square _bufferPos = _bufferIntr.ToSquares[i];

					// RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;

						if (_bufferPos.X > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;

						if (_bufferPos.X < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.Y++;

						if (_bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.Y--;

						if (_bufferPos.X < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP-RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;
						_bufferPos.Y++;

						if (_bufferPos.X > 7 || _bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP-LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;
						_bufferPos.Y++;

						if (_bufferPos.X < 0 || _bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN-RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;
						_bufferPos.Y--;

						if (_bufferPos.X > 7 || _bufferPos.Y < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN-LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;
						_bufferPos.Y--;

						if (_bufferPos.X < 0 || _bufferPos.Y < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type != PieceType.Rosace)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace)
							power = !power;
					}
				}

				// Checking for (powerful) Rosaces WITH obstacles inbetween				
				for (int i = 0; i < _bufferIntr.ToSquares.Count; i++)
				{
					Square _bufferPos = _bufferIntr.ToSquares[i];

					// RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;

						if (_bufferPos.X > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;

						if (_bufferPos.X < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.Y++;

						if (_bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.Y--;

						if (_bufferPos.X < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP-RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;
						_bufferPos.Y++;

						if (_bufferPos.X > 7 || _bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// UP-LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;
						_bufferPos.Y++;

						if (_bufferPos.X < 0 || _bufferPos.Y > 7)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN-RIGHT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X++;
						_bufferPos.Y--;

						if (_bufferPos.X > 7 || _bufferPos.Y < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

					_bufferPos = _bufferIntr.ToSquares[i];

					// DOWN-LEFT
					foreach (PieceState item in m_board.Pieces)
					{
						_bufferPos.X--;
						_bufferPos.Y--;

						if (_bufferPos.X < 0 || _bufferPos.Y < 0)
							break;

						if (item.Square == _bufferPos && item.Piece.Type == PieceType.Rosace && CheckPower(item.Piece))
							power = !power;
					}

				}
			}


			return power;
		}