Exemple #1
0
        public System.Drawing.Color PickRandomColor()
        {
            Array      values         = Enum.GetValues(typeof(ColorsEnum));
            ColorsEnum randomColorKey = (ColorsEnum)values.GetValue(StaticRandom.Instance.Next(values.Length));

            return(Colors[randomColorKey]);
        }
Exemple #2
0
        /// <summary>
        /// Returns a consistent index into an array size NUMBER_OF_COLORS.
        /// </summary>
        /// <returns>
        /// The index value for the color
        /// </returns>
        /// <param name='c'>
        /// The color to index into
        /// </param>
        /// <exception cref='NotImplementedException'>
        /// Is thrown if <see cref="ColorsEnum"/> is not consistent with this implementation.
        /// </exception>
        public static int ColorsEnumToIndex(ColorsEnum c)
        {
            switch (c)
            {
            case ColorsEnum.White:
                return(0);

            case ColorsEnum.Blue:
                return(1);

            case ColorsEnum.Black:
                return(2);

            case ColorsEnum.Red:
                return(3);

            case ColorsEnum.Green:
                return(4);

            case ColorsEnum.Colorless:
                return(5);
            }

            throw new NotImplementedException("Update this function to match ColorsEnum!");
        }
Exemple #3
0
    public static bool isCheck(ColorsEnum color, GameManager gameManager)
    {
        Square       kingSquare      = GetKingSquareForPlayer(color, gameManager);
        List <Piece> attackingPieces = gameManager.getPiecesOfColor(Utils.NegateColor(color));

        return(IsSquareUnderAttack(attackingPieces, kingSquare));
    }
Exemple #4
0
        /// <summary>
        /// Sets the colors.
        /// </summary>
        /// <returns>
        /// The colors.
        /// </returns>
        /// <param name='c'>
        /// The ColorEnum to set.
        /// </param>
        /// <param name='manaCost'>
        /// Mana cost string to parse.
        /// </param>
        public static ColorsEnum SetColors(this ColorsEnum c, string manaCost)
        {
            string lmanaCost = manaCost.ToLower();

            if (lmanaCost.Contains("w"))
            {
                c |= ColorsEnum.White;
            }
            if (lmanaCost.Contains("u"))
            {
                c |= ColorsEnum.Blue;
            }
            if (lmanaCost.Contains("b"))
            {
                c |= ColorsEnum.Black;
            }
            if (lmanaCost.Contains("r"))
            {
                c |= ColorsEnum.Red;
            }
            if (lmanaCost.Contains("g"))
            {
                c |= ColorsEnum.Green;
            }

            return(c);
        }
Exemple #5
0
        static string PrepareStringForColor(string elementTypeInCSharp, string valueAsString)
        {
            try
            {
                int colorAsInt;
                // Check if the color is a named color:
                if (!valueAsString.StartsWith("#"))
                {
                    ColorsEnum namedColor = (ColorsEnum)Enum.Parse(typeof(ColorsEnum), valueAsString, true);
                    colorAsInt = (int)namedColor;
                }
                else
                {
                    valueAsString = valueAsString.Replace("#", "");
                    if (valueAsString.Length == 6) // This is becaue XAML is tolerant when the user has forgot the alpha channel (eg. #DDDDDD for Gray).
                    {
                        valueAsString = "FF" + valueAsString;
                    }

                    colorAsInt = int.Parse(valueAsString.Replace("#", ""), NumberStyles.HexNumber);
                }
                string result = string.Format("new {0}() {{ A = (byte){1}, R = (byte){2}, G = (byte){3}, B = (byte){4} }}",
                                              elementTypeInCSharp,         //{0}
                                              (colorAsInt >> 0x18) & 0xff, //{1}
                                              (colorAsInt >> 0x10) & 0xff, //{2}
                                              (colorAsInt >> 8) & 0xff,    //{3}
                                              colorAsInt & 0xff);          //{4}
                return(result);
            }
            catch (Exception ex)
            {
                throw new wpf::System.Windows.Markup.XamlParseException("Invalid color: " + valueAsString, ex);
            }
        }
Exemple #6
0
    public static Square GetKingSquareForPlayer(ColorsEnum playerColor, GameManager gameManager)
    {
        Piece king           = gameManager.getPiecesOfColor(playerColor).Find(piece => piece.Type == PieceControllerType.KING);
        char  chessNotationX = ConvertLineToChessNotation((int)king.coordinates.x);
        char  chessNotationY = ConvertColumnToChessNotation((int)king.coordinates.y);

        char[] charKey = { chessNotationY, chessNotationX };
        return(Board.SquareMapping[new string(charKey)]);
    }
Exemple #7
0
 void ToggleAtMove()
 {
     if (AtMove == ColorsEnum.BLACK)
     {
         AtMove = ColorsEnum.WHITE;
     }
     else
     {
         AtMove = ColorsEnum.BLACK;
     }
 }
Exemple #8
0
 public void ChangeTurn()
 {
     if (ColorsTurn == ColorsEnum.White)
     {
         ColorsTurn = ColorsEnum.Black;
     }
     else
     {
         ColorsTurn = ColorsEnum.White;
     }
 }
 public StackObject(StackObjectType objectType, string typeString, string text,
                    Player owner, Player controller, ColorsEnum colors,
                    GameActionDelegate resolutionAction)
 {
     ObjectType       = objectType;
     TypeString       = typeString;
     Text             = text;
     Owner            = owner;
     Controller       = controller;
     Colors           = colors;
     ResolutionAction = resolutionAction;
 }
Exemple #10
0
        public StackObject(StackObjectType objectType, string typeString, string text, 
		                   Player owner, Player controller, ColorsEnum colors, 
		                   GameActionDelegate resolutionAction)
        {
            ObjectType = objectType;
            TypeString = typeString;
            Text = text;
            Owner = owner;
            Controller = controller;
            Colors = colors;
            ResolutionAction = resolutionAction;
        }
Exemple #11
0
        /// <summary>
        /// Returns true if c is multicolored
        /// </summary>
        /// <param name='c'>
        /// The ColorEnum to check.
        /// </param>
        public static bool Multicolor(this ColorsEnum c)
        {
            // determine if it's multicolor by checking if c is a power of 2 or a power of 2 + 1
            double cInDouble  = (double)c;
            double logC       = Math.Log(cInDouble, 2);
            double logCMinus1 = Math.Log(cInDouble - 1, 2);

            if (cInDouble != 0 && (logC - Math.Truncate(logC) == 0 || logCMinus1 - Math.Truncate(logCMinus1) == 0))
            {
                return(true);
            }
            return(false);
        }
        public void ChangeTurn()
        {
            IChessTimer ct = new StandardChessTimer(new StandardPlayer("A"), new StandardPlayer("B"));
            ColorsEnum  startingTurnColor = ct.ColorsTurn;
            ColorsEnum  secondTurnColor, thirdTurnColor;

            ct.ChangeTurn();
            secondTurnColor = ct.ColorsTurn;
            ct.ChangeTurn();
            thirdTurnColor = ct.ColorsTurn;

            Assert.Equal(ColorsEnum.White, startingTurnColor);
            Assert.Equal(ColorsEnum.Black, secondTurnColor);
            Assert.Equal(ColorsEnum.White, thirdTurnColor);
        }
Exemple #13
0
 void HandleEndTurnEvent(ColorsEnum colorAtMove, bool isCheck)
 {
     if (colorAtMove != playerColor)
     {
         if (isCheck == true)
         {
             playerStatus.text  = PlayerStatusConstants.IN_CHECK;
             playerStatus.color = Color.red;
         }
         else
         {
             playerStatus.text = PlayerStatusConstants.THINKING;
         }
     }
     else
     {
         playerStatus.text = PlayerStatusConstants.NO_STATUS;
     }
 }
Exemple #14
0
        public bool VerifyKingPosition(IChessPiece pieceMoved, string finalPositionString,
                                       List <IChessPiece> chessPieces, ColorsEnum colorChecked)
        {
            Position    finalPosition = new Position(finalPositionString);
            IChessPiece currentKing   = chessPieces.Where(cp => cp.Name == "King" && cp.Color == colorChecked).FirstOrDefault();
            //Create a piece that will temporarily replace piece that is moving but at the final position
            IChessPiece dummyPiece = new Pawn((int)colorChecked, finalPositionString);

            if (currentKing == pieceMoved)
            {
                dummyPiece = new King((int)colorChecked, finalPositionString);
            }
            IChessPiece pieceTaken = chessPieces.Where(cp => cp.Position.ColumnPosition == finalPosition.ColumnPosition && cp.Position.RowPosition == finalPosition.RowPosition).FirstOrDefault();

            chessPieces.Remove(pieceMoved);
            //if(pieceTaken != null)
            chessPieces.Remove(pieceTaken);
            chessPieces.Add(dummyPiece);

            //Check if after the fake move king of the moving color is checked
            bool result = VerifyPosition(currentKing.Position, chessPieces, colorChecked);

            //If king is the moving piece we have to verify the new position
            if (dummyPiece.Name == "King")
            {
                result = VerifyPosition(dummyPiece.Position, chessPieces, colorChecked);
            }

            //Remove dummy and give back the pieces that were there at the beggining so that the reference type data won t be changed
            chessPieces.Remove(dummyPiece);
            if (pieceMoved != null)
            {
                chessPieces.Add(pieceMoved);
            }
            if (pieceTaken != null)
            {
                chessPieces.Add(pieceTaken);
            }

            return(result);
        }
        public Bitmap[] ExtractCharacters(Bitmap imageBitmap, ColorsEnum?color = null)
        {
            ImageToMatrix imageToMatrix = new ImageToMatrix();

            imageBitmap = new Bitmap(imageBitmap, new Size(260, 51));

            List <Bitmap> charactersBitmap = new List <Bitmap>();

            foreach (int delimiter in _delimiters)
            {
                Bitmap character = imageBitmap
                                   .Clone(new Rectangle {
                    X = delimiter, Y = 8, Width = 27, Height = 29
                }, imageBitmap.PixelFormat);

                charactersBitmap.Add(character);
            }

            if (color != null)
            {
                List <Bitmap> charactersBitmapColor = new List <Bitmap>();
                foreach (Bitmap character in charactersBitmap)
                {
                    imageToMatrix.Convert(character, out Color[][] imageColors);
                    Color characterColor = imageColors.SelectMany(c => c).GroupBy(c => c.Name).OrderByDescending(g => g.Count()).ElementAt(1).ElementAt(0);

                    ColorsEnum result = ColorDecoder.Decode(characterColor);
                    if (result.Equals(color))
                    {
                        charactersBitmapColor.Add(character);
                    }
                }

                charactersBitmap = charactersBitmapColor;
            }

            return(charactersBitmap.ToArray());
        }
Exemple #16
0
        public ColorsEnum?Verify()
        {
            //Check if king will be checked after the current move
            List <IChessPiece> currentColorPieces          = Game.chessBoard.ChessPiecesOnBoard.Where(cp => cp.Color == Game.chessTimer.ColorsTurn).ToList();
            List <string>      currentColorPiecesPositions = currentColorPieces.Select(cp => cp.Position.ToString()).ToList();

            foreach (string positionString in currentColorPiecesPositions)
            {
                int boardHightBoundary = Game.chessBoard.UpperRightCorner.RowPosition;
                int boardWidthBoundary = Game.chessBoard.UpperRightCorner.ColumnPosition;
                for (int i = 1; i <= boardWidthBoundary; i++)
                {
                    for (int j = 1; j <= boardHightBoundary; j++)
                    {
                        var  movedPiece     = Game.chessBoard.GetAPieceFromPosition(positionString);
                        bool isMovePossible = movedPiece.IsMovePossible(i, j, Game.chessBoard.ChessPiecesOnBoard);
                        if (!isMovePossible)
                        {
                            continue;
                        }

                        Position finalPosition     = new Position(i, j);
                        bool     willKingBeChecked = positionCheckedVerifier.VerifyKingPosition(movedPiece, finalPosition.ToString(),
                                                                                                Game.chessBoard.ChessPiecesOnBoard, Game.chessTimer.ColorsTurn);
                        if (!willKingBeChecked && isMovePossible)
                        {
                            return(null);
                        }
                    }
                }
            }

            ColorsEnum currentColor = Game.chessTimer.ColorsTurn;

            return(currentColor == ColorsEnum.White ? ColorsEnum.Black : ColorsEnum.White);
        }
Exemple #17
0
    public static GameObject InstantiatePieceAndPlaceOnSquare(string name, PieceControllerType type, ColorsEnum color, string destinationSquare)
    {
        GameObject newPiece = Utils.CreatePieceGameObject(name, type, color);
        Square     square   = Board.SquareMapping[destinationSquare];

        Utils.PlaceOnObject(newPiece, square.gameObject);

        return(newPiece);
    }
Exemple #18
0
    public static GameObject CreatePieceGameObject(string name, PieceControllerType type, ColorsEnum color)
    {
        GameObject newGameObject = new GameObject(name);

        newGameObject.AddComponent <Piece>();
        Piece PieceComponent = newGameObject.GetComponent <Piece>();

        PieceComponent.IPiece = PieceFactory.createInstance(type);
        PieceComponent.Type   = type;
        PieceComponent.SetColor(color);

        return(newGameObject);
    }
Exemple #19
0
 public bool IsAvailableForMove(ColorsEnum pieceColor)
 {
     return(GetPiece() == null || GetPiece().GetColor() != pieceColor);
 }
Exemple #20
0
        public bool VerifyPosition(string positionString, List <IChessPiece> chessPieces, ColorsEnum colorChecked)
        {
            Position position = new Position(positionString);

            return(VerifyPosition(position, chessPieces, colorChecked));
        }
Exemple #21
0
 public int this[ColorsEnum color]
 {
     get { return(pool[Conversions.ColorsEnumToIndex(color)]); }
     set { pool[Conversions.ColorsEnumToIndex(color)] = value; }
 }
Exemple #22
0
        /// <summary>
        /// Returns a consistent index into an array size NUMBER_OF_COLORS.
        /// </summary>
        /// <returns>
        /// The index value for the color
        /// </returns>
        /// <param name='c'>
        /// The color to index into
        /// </param>
        /// <exception cref='NotImplementedException'>
        /// Is thrown if <see cref="ColorsEnum"/> is not consistent with this implementation.
        /// </exception>
        public static int ColorsEnumToIndex(ColorsEnum c)
        {
            switch(c)
            {
                case ColorsEnum.White:
                    return 0;
                case ColorsEnum.Blue:
                    return 1;
                case ColorsEnum.Black:
                    return 2;
                case ColorsEnum.Red:
                    return 3;
                case ColorsEnum.Green:
                    return 4;
                case ColorsEnum.Colorless:
                    return 5;
            }

            throw new NotImplementedException("Update this function to match ColorsEnum!");
        }
Exemple #23
0
 public void SetColor(ColorsEnum value)
 {
     color = value;
 }
Exemple #24
0
 public int this[ColorsEnum color]
 {
     get { return pool[Conversions.ColorsEnumToIndex(color)]; }
     set { pool[Conversions.ColorsEnumToIndex(color)] = value; }
 }
Exemple #25
0
 void HandleEndTurnEvent(ColorsEnum colorAtMove, bool isCheck)
 {
     Utils.ToggleDraggableForPieces(FindObjectsOfType <Piece>());
     ToggleAtMove();
     // HandlePossibleChess(colorAtMove);
 }
Exemple #26
0
        public bool VerifyPosition(Position position, List <IChessPiece> chessPieces, ColorsEnum colorChecked)
        {
            bool IsPositionChecked = false;
            List <IChessPiece> enemyChessPieces = chessPieces.Where(cp => cp.Color != colorChecked).ToList();

            foreach (IChessPiece cp in enemyChessPieces)
            {
                if (cp.IsMovePossible(position.ColumnPosition, position.RowPosition, chessPieces))
                {
                    IsPositionChecked = true;
                    break;
                }
            }
            return(IsPositionChecked);
        }
Exemple #27
0
 public List <Piece> getPiecesOfColor(ColorsEnum color)
 {
     return(color == ColorsEnum.BLACK ? blackPieces : whitePieces);
 }
Exemple #28
0
 public Knight(ColorsEnum color, Tuple <int, int> position = null)
 {
     Color    = color;
     Position = position != null ? position : new Tuple <int, int>(-1, -1);
     Symbol   = '1';
 }
Exemple #29
0
 public static ColorsEnum NegateColor(ColorsEnum color)
 {
     return(color == ColorsEnum.BLACK ? ColorsEnum.WHITE : ColorsEnum.BLACK);
 }
 public string GetColor(ColorsEnum color)
 //public string GetColor(string color)
 {
     return(color.ToString());
 }
Exemple #31
0
 /// <summary>
 /// Gets the number of mana symbols of the specified <see cref="ColorsEnum">color</see>
 /// </summary>
 /// <param name='color'>
 /// Color.
 /// </param>
 public int this[ColorsEnum color]
 {
     get { return(coloredSymbols[Conversions.ColorsEnumToIndex(color)]); }
     private set { coloredSymbols[Conversions.ColorsEnumToIndex(color)] = value; }
 }