Exemplo n.º 1
0
    //TODO 汚い
    // 引数のidと隣接したidを返す
    static public List <int> NextIDs(int id, PIECE_COLOR turn)
    {
        var list = new List <int>();

        for (int i = 0; i < 3; i++)
        {
            list.Add(id - 6 + i);
            list.Add(id - 1 + i);
            list.Add(id + 4 + i);
        }
        list.Remove(id);
        if (id % 5 == 0)   //up
        {
            list.Remove(id - 6);
            list.Remove(id - 1);
            list.Remove(id + 4);
        }
        if (id % 5 == 4) //down
        {
            list.Remove(id - 4);
            list.Remove(id + 1);
            list.Remove(id + 6);
        }
        if (0 <= id && id <= 4) //left
        {
            list.Remove(id - 6);
            list.Remove(id - 5);
            list.Remove(id - 4);
            if (turn == PIECE_COLOR.BLACK)
            {
                list.Add(25);
            }
        }
        if (20 <= id && id <= 24) //right
        {
            list.Remove(id + 4);
            list.Remove(id + 5);
            list.Remove(id + 6);
            if (turn == PIECE_COLOR.WHITE)
            {
                list.Add(26);
            }
        }
        return(list);
    }
Exemplo n.º 2
0
 public CheckerPiece(PIECE_COLOR color, string textureName)
 {
     Color = color;
     PieceType = PIECE_TYPE.PAWN;
     this.textureName = textureName;
 }
Exemplo n.º 3
0
 private void SetCheckerPieces(ContentManager contentManager, ref CheckerPlayer checkerPlayer, PIECE_COLOR color, string textureName, int iStart, int iEnd)
 {
     checkerPlayer = new CheckerPlayer(contentManager, color);
     CheckerPiece piece = new CheckerPiece(color, textureName);
     piece.LoadContent(contentManager);
     for (int i = iStart; i < iEnd; ++i)
     {
         int jStart = i & 1;
         for (int j = jStart; j < 8; j += 2)
         {
             CheckerPiece newPiece = piece.Clone() as CheckerPiece;
             newPiece.Position = new Point(j, i);
             pieces.Add(newPiece);
             checkerPlayer.Pieces.Add(piece);
             checkerBoard.Grid[j, i].CheckerPiece = newPiece;
             checkerPlayer.Pieces.Add(piece);
         }
     }
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            init();
            Console.WriteLine("Type \"help\" to see all supported commands.");
            bool exit = false;

            while (!exit)
            {
                Console.Write("$ ");
                string input = Console.ReadLine();

                string cmdPattern = "^([a-zA-Z]+)";
                Match  m          = Regex.Match(input, cmdPattern, RegexOptions.IgnoreCase);
                if (m.Success)
                {
                    string cmd = m.Value.ToLower();
                    Console.WriteLine(cmd);
                    switch (cmd)
                    {
                    case "help":
                        Console.WriteLine("place command");
                        Console.WriteLine("    structure: place type name color row column");
                        Console.WriteLine("    example:   place knight w_knig_1 white 1 2");
                        Console.WriteLine("move command");
                        Console.WriteLine("    structure: move current_row current_column target_row target column");
                        Console.WriteLine("    example:   move 1 2 2 5");
                        Console.WriteLine("show command");
                        Console.WriteLine("    structure: show");
                        Console.WriteLine("exit command");
                        Console.WriteLine("    structure: exit");
                        Console.WriteLine("help command");
                        Console.WriteLine("    structure: help");
                        break;

                    case "exit":
                        exit = true;
                        break;

                    case "move":
                        // move source.r source.c target.r target.c
                        string movePattern = @"(\d+)";
                        int[]  num         = { 0, 0, 0, 0 };
                        Regex.Matches(input, movePattern);
                        int i = 0;
                        foreach (Match match in Regex.Matches(input, movePattern, RegexOptions.IgnoreCase))
                        {
                            num[i] = Int32.Parse(match.Value);
                            i++;
                        }
                        Console.WriteLine($"Move {board.ChessBoard[num[0], num[1]].Name} [{num[0]}, {num[1]}] -> [{num[2]}, {num[3]}]");
                        bool result = board.MoveAPiece(new Position {
                            Row = num[0], Column = num[1]
                        }, new Position {
                            Row = num[2], Column = num[3]
                        });
                        Console.WriteLine(result);
                        break;

                    case "show":
                        board.PrintBoard();
                        break;

                    case "place":
                        // place type name color position.r position.c
                        string placePattern = @"place\s+([a-zA-Z]+)\s+(\w+)\s+([a-zA-Z]+)\s+([0-9]+)\s+([0-9]+)";
                        m = Regex.Match(input, placePattern, RegexOptions.IgnoreCase);
                        if (m.Success)
                        {
                            Console.WriteLine($"{m.Groups[0]}, {m.Groups[1]}, {m.Groups[2]}, {m.Groups[3]},  {m.Groups[4]}, {m.Groups[5]}");

                            string     typeName = m.Groups[1].ToString().ToLower();
                            PIECE_TYPE type     = PIECE_TYPE.Invalid;
                            try
                            {
                                type = (PIECE_TYPE)Enum.Parse(typeof(PIECE_TYPE), typeName, true);
                            }
                            catch (ArgumentException) { }

                            string name = m.Groups[2].ToString().ToLower();


                            string      colorName = m.Groups[3].ToString().ToLower();
                            PIECE_COLOR color     = PIECE_COLOR.Invalid;
                            try
                            {
                                color = (PIECE_COLOR)Enum.Parse(typeof(PIECE_COLOR), colorName, true);
                            }
                            catch (ArgumentException) {}

                            Position position = new Position {
                                Row    = Int32.Parse(m.Groups[4].ToString()),
                                Column = Int32.Parse(m.Groups[5].ToString())
                            };

                            if (type != PIECE_TYPE.Invalid && color != PIECE_COLOR.Invalid)
                            {
                                Console.WriteLine($"place {type.ToString()}  {name} to [{position.Row}, {position.Column}]");
                                switch (type)
                                {
                                case PIECE_TYPE.King:
                                    board.PlaceAPiece(new King {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                case PIECE_TYPE.Queen:
                                    board.PlaceAPiece(new Queen {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                case PIECE_TYPE.Rook:
                                    board.PlaceAPiece(new Rook {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                case PIECE_TYPE.Bishop:
                                    board.PlaceAPiece(new Bishop {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                case PIECE_TYPE.Knight:
                                    board.PlaceAPiece(new Knight {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                case PIECE_TYPE.Pawn:
                                    board.PlaceAPiece(new Pawn(1)
                                    {
                                        Color = color, Name = name
                                    }, position);
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 5
0
 public CheckerPlayer(ContentManager contentManager, PIECE_COLOR color)
 {
     CheckerPlayerController = new CheckerPlayerController(contentManager, this);
     Color = color;
 }