Ejemplo n.º 1
0
        // Console project for testing
        static void Main(string[] args)
        {
            var           rand = new Random();
            List <string> list;
            var           chess = new Chess.Chess();

            while (true)
            {
                list = (List <string>)chess.GetAllMoves();
                Console.WriteLine(chess.Fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheck ? "CHECK" : "-");
                foreach (string moves in chess.GetAllMoves())
                {
                    Console.Write(moves + "\t");
                }
                Console.Write("\n> ");
                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = list[rand.Next(list.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Random rnd = new Random();

            Chess.Chess   chess = new Chess.Chess();
            List <string> moves;

            while (true)
            {
                moves = chess.GetAllMoves();
                Console.WriteLine(chess.fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheck() ? "CHECK" : "");

                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = moves[rnd.Next(moves.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Random random = new Random();

            Chess.Chess   chess = new Chess.Chess("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
            List <string> list;

            while (true)
            {
                list = chess.GetAllMoves();
                Console.WriteLine(chess.fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheck() ? "CHECK" : "~");
                foreach (string moves in list)
                {
                    Console.Write(moves + "\t");
                }
                Console.WriteLine();
                Console.Write("> ");
                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = list[random.Next(list.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Random random = new Random();

            Chess.Chess   chess = new Chess.Chess("rnbqkbnr/1p1111p1/8/8/8/8/1P1111P1/RNBQKBNR w KQkq - 0 1");
            List <string> list;

            // Выводит игру на консоль
            while (true)
            {
                list = chess.GetAllMoves();
                Console.WriteLine(chess.fen);
                Print(ChessToAscii(chess));
                foreach (string moves in list)
                {
                    Console.Write(moves + "\t");
                }
                Console.WriteLine();
                Console.Write("> ");
                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = list [random.Next(list.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 5
0
 public void GetFigureAtTestValid()
 {
     // -- Arrange
     var chess = new Chess.Chess();
     // -- Act
     // -- Assert
 }
Ejemplo n.º 6
0
        private static void AIChess()
        {
            Random random = new Random();

            Chess.Chess   chess = new Chess.Chess("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
            List <string> list;

            while (true)
            {
                list = chess.GetAllMoves();
                Console.WriteLine(chess.fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheck() ? "Шах" : "");
                foreach (string moves in chess.GetAllMoves())
                {
                    Console.Write(moves + "\n");
                }
                Console.WriteLine();
                Console.Write("< ");
                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                try
                { if (move == "")
                  {
                      move = list[random.Next(list.Count)];
                  }
                }
                catch (Exception) { }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 7
0
        static string ChessToAscii(Chess.Chess chess)
        {
            string text   = "  +-----------------+\n";
            string reserv = "  +-----------------+\n";

            for (int y = 7; y >= 0; y--)
            {
                text += y + 1;
                text += " | ";
                for (int x = 0; x < 8; x++) //здесь исправить в GetFigureAt параметры на string xy
                {
                    //конвертируем в строку
                    string fromX = Convert.ToString(x);
                    string fromY = Convert.ToString(y);
                    string xy    = fromX + fromY;

                    text   += chess.GetFigureAt(x, y) + " ";
                    reserv += chess.StringFigure(xy) + " ";
                }
                text   += "|\n";
                reserv += "|\n";
            }
            text += "  +-----------------+\n";
            text += "    a b c d e f g h\n";

            reserv += "  +-----------------+\n";
            reserv  = "    a b c d e f g h\n";

            return(text);
        }
Ejemplo n.º 8
0
    async void MakeMove(string move)
    {
        makeMove = true;
        flag     = false;
        for (int y = 0; y < 8; y++)
        {
            for (int x = 0; x < 8; x++)
            {
                MarkSquare(x, y, false);
            }
        }
        GameInfo info = await refBoard.SendMove(move);

        chess        = new Chess.Chess(info.FEN);
        currentColor = chess.fen.Split()[1] == "w" ? "white" : "black";
        if (chess.IsCheckAndMate())
        {
            isPlaying         = false;
            gameOverText.text = "Вы победили!!!";
            gameOverCanvas.SetActive(true);
            Draw.SetActive(false);
        }
        ShowFigures();
        makeMove = false;
        flag     = true;
    }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            Random random = new Random();

            Chess.Chess   chess = new Chess.Chess();
            List <string> list;

            while (true)
            {
                list = chess.GetAllMoves();
                Console.WriteLine(chess.fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheak() ? "Chek" : "");
                foreach (string moves in list)
                {
                    Console.Write(moves + "\t");
                }
                Console.WriteLine();
                Console.Write("Your turn >");
                string move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = list[random.Next(list.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 10
0
    // Use this for initialization
    IEnumerator Start()
    {
        user = PlayerPrefs.GetString("name");
        user = user.Replace('"', ' ').Trim();
        dad  = new DragAndDrop();


        create   = new ChessClient.ChessClient(HOST, user);
        refBoard = new ChessClient.ChessClient(HOST, user);
        try
        {
            CreateGame();
        }
        catch
        {
            GameInfo info = refBoard.GetCurrentGame().Result;
            chess = new Chess.Chess(info.FEN);
        }

        if (isPlaying)
        {
            while (true)
            {
                yield return(new WaitForSeconds(0.7f));

                Refresh();
            }
        }
    }
Ejemplo n.º 11
0
        static void Main(string[] args)
        {
            Random random = new Random();
            var    chess  = new Chess.Chess();//"rnbqkbnr/1p1111p1/8/8/8/8/1P1111P1/RNBQKBNR w KQkq - 0 1");

            while (true)
            {
                var list = chess.GetAllMoves();
                Console.WriteLine(chess.Fen);
                Print(ChessToAscii(chess));
                Console.WriteLine(chess.IsCheck() ? "Check" : "-");
                foreach (var moves in list)
                {
                    Console.Write(moves + "\t");
                }

                Console.WriteLine();
                Console.Write("> ");
                var move = Console.ReadLine();
                if (move == "q")
                {
                    break;
                }
                if (move == "")
                {
                    move = list[random.Next(list.Count)];
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 12
0
        //создать новую игру
        private Game CreateNewGame()
        {
            Game game = new Game();

            Chess.Chess chess = new Chess.Chess();
            game.FEN    = chess.fen;
            game.Status = "play";

            db.Games.Add(game);
            db.SaveChanges();

            return(game);
        }
Ejemplo n.º 13
0
        static void Main(string[] args)
        {
            Chess.Chess chess = new Chess.Chess();

            while (true)
            {
                Console.WriteLine(chess.fem);
                string move = Console.ReadLine();
                if (move == "")
                {
                    break;
                }
                chess = chess.Move(move);
            }
        }
Ejemplo n.º 14
0
 static void Main(string[] args)
 {
     Chess.Chess chess = new Chess.Chess(); // Создаем объект "chess" класса "Chess" из подключенного пространства имен "Chess". Пространство имен у нас совпадает с названием класса, пожтому нам приходится объявлять класс таким образом "Chess.Chess".
     while (true)
     {
         Console.WriteLine(chess.fen);          // Выводим значение "fen" на экран.
         Console.WriteLine(ChesToAscii(chess)); // Выводим на экнан содержимое метода ChesToAscii с переданным в него параметром "chess" 'этот параметр представляет так же объект шахмат которые мы построили
         string move = Console.ReadLine();      // Переменная "move" записывает в себя ход который намеривается осуществить игрок.
         if (move == "")
         {
             break;
         }
         chess = chess.Move(move);  // Наша сущьность "chess" берет на себя новое значение передавая аргумент "move"
     }
 }
Ejemplo n.º 15
0
        static void Main(string[] args) //******надо проверить, когда ходят фигуры: когда меняется цвет
        {
            Chess.Chess chess = new Chess.Chess();
            // Chess.Chess chess = new Chess.Chess();
            List <string> list;

            Random random = new Random();

            while (true)
            {
                try
                {
                    list = chess.GetAllMoves();

                    Console.WriteLine(chess.fen);
                    Print(ChessToAscii(chess));
                    Console.WriteLine(chess.IsCheck() ? "CHECK" : "-");

                    /*******************/
                    //Console.WriteLine(chess.IsMate() ? "CHECKMATE" : "-");
                    /*******************/

                    foreach (string moves in list) //ищем доступные ходы для фигур
                    {
                        Console.Write(moves + "\t");
                    }

                    Console.WriteLine();
                    Console.Write("> ");
                    string move = Console.ReadLine();
                    if (move == "q")
                    {
                        break;
                    }

                    if (move == "")
                    {
                        move = list[random.Next(list.Count)];
                    }
                    chess = chess.Move(move); //объект содержит метод хода фигуры
                }
                catch (ArgumentOutOfRangeException ex)
                {
                    Console.WriteLine($"Возникло исключение {ex.Message}");
                    Console.WriteLine("мат: " + chess.Mate());
                }
            }
        }
Ejemplo n.º 16
0
 // Update is called once per frame
 void Update()
 {
     if (dad.Action())
     {
         string from = GetSquare(dad.pickPosition);
         Debug.Log("from :" + from);
         string to = GetSquare(dad.dropPosition);
         Debug.Log("to :" + to);
         string figure = chess.GetFigureAt(GetSquareX(dad.pickPosition), GetSquareY(dad.pickPosition)).ToString();
         Debug.Log("figure :" + figure);
         string move = figure + from + to;
         Debug.Log("Move :" + move);
         chess = chess.Move(move);
         ShowFigures();
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Set up a new game for the specified number of players.
        /// </summary>
        private void NewGame(int nPlayers)
        {
            // clean up all of the things first
            if (!m_manualBoard) Stop();

            // create new game for number of players
            m_aigame = (nPlayers == 0);
            chess = new Chess(this, nPlayers, !m_manualBoard);

            // show turn status
            SetTurn(Player.WHITE);
            SetStatus(false, "White's turn");

            // reset timers
            m_whiteTime = new TimeSpan(0);
            m_blackTime = new TimeSpan(0);
            lblWhiteTime.Text = m_whiteTime.ToString("c");
            lblBlackTime.Text = m_blackTime.ToString("c");

            // show ai difficulty
            if (nPlayers < 2)
            {
                LogMove("AI Difficulty " + (string)temp.Tag + "\n");
            }

            if (m_manualBoard)
            {
                // allow setting up the board
                SetStatus(false, "You may now place pieces via the menu.");
                setPieceToolStripMenuItem.Enabled = true;
            }
            else
            {
                // start the game
                SetStatus(false, "White's Turn");
                if (m_aigame)
                {
                    new Thread(chess.AISelect).Start();
                }
                tmrWhite.Start();
            }

            // allow stopping the game
            endCurrentGameToolStripMenuItem.Enabled = true;
        }
Ejemplo n.º 18
0
        static string ChesToAscii(Chess.Chess chess)
        {
            string text = "  +-----------------+\n"; // Оформление.

            for (int y = 7; y >= 0; y--)
            {
                text += y + 1; // Нумеруем поля
                text += " | "; // Оформление
                for (int x = 0; x < 8; x++)
                {
                    text += chess.GetFigureAt(x, y) + " ";
                }
                text += "|\n";                 // Оформление
            }
            text += "  +-----------------+\n"; // Оформление
            text += "    a b c d e f g h\n";
            return(text);
        }
Ejemplo n.º 19
0
        static string ChessToAscii(Chess.Chess chess)
        {
            string text = "  +-----------------+\n";

            for (int y = 7; y >= 0; y--)
            {
                text += y + 1;
                text += " | ";
                for (int x = 0; x < 8; x++)
                {
                    text += chess.GetFigureAt(x, y) + " ";
                }
                text += "|\n";
            }
            text += "  +-----------------+\n";
            text += "    a b c d e f g h\n";
            return(text);
        }
Ejemplo n.º 20
0
    void Update()
    {
        //проверка хода
        if (dad.Action())
        {
            string from = GetSquare(dad.pickPosition);
            string to   = GetSquare(dad.dropPosition);
            //ход
            string figure = chess.GetFigureAt((int)(dad.pickPosition.x / 2.0), (int)(dad.pickPosition.y / 2.0)).ToString();
            string move   = figure + from + to; //Pa2a2 (Pa3a3)
            Debug.Log(move);

            chess = chess.Move(move);
            ShowFigures();
            MarkValidFigures();
        }
        //dad.Action();
    }
 static void Main(string[] args)
 {
     Chess.Chess chess = new Chess.Chess();
     while (true)
     {
         Console.WriteLine(chess.fen);
         Console.WriteLine(ChessToAscii(chess));
         foreach (string moves in chess.GetAllMoves())
         {
             Console.Write(moves + "\t");
         }
         Console.WriteLine();
         Console.Write(">");
         string move = Console.ReadLine();
         if (move == "")
         {
             break;
         }
         chess = chess.Move(move);
     }
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Stop all current activity / games and reset everything.
        /// </summary>
        private void Stop()
        {
            SetStatus(false, "Choose New Game or Manual Board.");

            // stop the ai and reset chess
            AI.STOP = true;
            chess = null;

            // reset turn indicator
            SetTurn(Player.WHITE);

            // reset timers
            tmrWhite.Stop();
            tmrBlack.Stop();
            m_whiteTime = new TimeSpan(0);
            m_blackTime = new TimeSpan(0);
            lblWhiteTime.Text = m_whiteTime.ToString("c");
            lblBlackTime.Text = m_blackTime.ToString("c");

            // clear the board ui and log
            SetBoard(new ChessBoard());
            txtLog.Text = "";

            // reset board status vars
            m_checkmate = false;
            m_aigame = false;
            m_finalizedBoard = false;

            // reset the menu
            manualBoardToolStripMenuItem.Enabled = true;
            endCurrentGameToolStripMenuItem.Enabled = false;
            if (m_finalizedBoard || m_manualBoard)
            {
                setPieceToolStripMenuItem.Enabled = false;
                manualBoardToolStripMenuItem.Checked = false;
            }
            endCurrentGameToolStripMenuItem.Enabled = false;
        }
Ejemplo n.º 23
0
        //game
        public Game MakeMove(int id, string move)
        {
            Game game = GetGame(id);

            if (game == null)
            {
                return(game);
            }

            if (game.Status == null)
            {
                return(game);
            }

            //передадим fen и ход с браузера
            Chess.Chess chess     = new Chess.Chess(game.FEN);
            Chess.Chess chessNext = chess.Move(move);

            if (chessNext.fen == game.FEN)
            {
                return(game);
            }

            //если принял ход
            game.FEN = chessNext.fen;

            //если мат/пат (?)
            if (chessNext.Mate())
            {
                game.Status = "done";
            }

            db.Entry(game).State = System.Data.Entity.EntityState.Modified;
            db.SaveChanges();

            return(game);
        }
Ejemplo n.º 24
0
 private void UnMakeMove(Movelist move, int chesstype,Chess[,] chess)
 {
     chess[move.from.Y, move.from.X].chesstype = chess[move.to.Y, move.to.X].chesstype;
     chess[move.to.Y, move.to.X].chesstype = chesstype;
 }
Ejemplo n.º 25
0
 private int IsGameOver(Chess[,] chess, int deep)
 {
     int i, j;
     bool RedLive = false, BlackLive = false;
     for(i = 0; i < 3; i++)
         for (j = 3; j < 6; j++)
         {
             if (chess[i, j].chesstype == 1)
                 BlackLive = true;
             if (chess[i, j].chesstype == 8)
                 RedLive = true;
         }
     for (i = 7; i < 10; i++)
         for (j = 3; j < 6; j++)
         {
             if (chess[i, j].chesstype == 8)
                 RedLive = true;
             if (chess[i, j].chesstype == 1)
                 BlackLive = true;
         }
     i = (MaxDeep - deep ) % 2;          
     if (!BlackLive)
         if (i==c)
             return 18888 + deep;
         else
             return -18888 - deep;
     if (!RedLive)
         if (i==c)
             return -18888 - deep;
         else
             return 18888 + deep;
     return 0;
 }
Ejemplo n.º 26
0
 public MainWindow()
 {
     Chess.Chess chess = new Chess.Chess(this);
     InitializeComponent();
 }
Ejemplo n.º 27
0
		private int Caculate(Chess[,] chess,bool side)
        {
			int i,j,k,chesstype,targettype;
			Attack=new int[10,9]
			{
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
			};
			Guard=new int[10,9]
			{
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
			};
			ChessValue=new int[10,9]
			{
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
			};
			ActiveValuePos=new int[10,9]
			{
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
				{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0},
			};
			for(i=0;i<10;i++)
				for(j=0;j<9;j++)
				{
					if(chess[i,j].chesstype!=0)
					{
						chesstype=chess[i,j].chesstype;
						GetRelation(chess,i,j);
						for(k=0;k<nRelation;k++)
						{
							targettype=chess[Relation[k].Y,Relation[k].X].chesstype;
							if(targettype==0)//没棋
								ActiveValuePos[i,j]++;
							else
							{
								if(IsSameSide(chesstype,targettype))//自己棋
									Guard[Relation[k].Y,Relation[k].X]++;
								else
								{
									Attack[Relation[k].Y,Relation[k].X]++;
									ActiveValuePos[i,j]++;
									switch(targettype)
									{
										case 1:
										{
                                            if (!side)
												return 18888;
											break;
										}
										case 8:
										{
											if(side)
												return 18888;
											break;
										}
										default:
										{
                                            Attack[Relation[k].Y, Relation[k].X] += (30 + (BaseValue[targettype - 1] - BaseValue[chesstype - 1]) / 10) / 10;
											break;
										}
									}
								}
							}
						}
					}
				}
			for(i=0;i<10;i++)
				for(j=0;j<9;j++)
				{
					if(chess[i,j].chesstype!=0)
					{
						chesstype=chess[i,j].chesstype;
						ChessValue[i,j]++;
						ChessValue[i,j]+=ActiveValue[chesstype-1]*ActiveValuePos[i,j];
						ChessValue[i,j]+=GetBingValue(chess,j,i);
					}
				}
			int HalfValue;
			for(i=0;i<10;i++)
				for(j=0;j<9;j++)
				{
					if(chess[i,j].chesstype!=0)
					{
						chesstype=chess[i,j].chesstype;
						HalfValue=BaseValue[chesstype-1]/16;
						ChessValue[i,j]+=BaseValue[chesstype-1];
						if(IsBlack(chesstype))
						{
							if(Attack[i,j]!=0)
							{
								if(side)
								{
									if(chesstype==1)
										ChessValue[i,j]-=20;
									else
									{
                                        ChessValue[i, j] -= HalfValue * 2;
										if(Guard[i,j]!=0)
                                            ChessValue[i, j] += HalfValue ;
									}
								}
								else
								{
									if(chesstype==1)
										return 18888;
									else
									{
                                        ChessValue[i, j] -= HalfValue  * 10;
                                        if (Guard[i, j] != 0)
                                            ChessValue[i, j] += HalfValue * 9;
									}
								}
                                ChessValue[i, j] -= Attack[i, j];
							}
							else
							{
								if(Guard[i,j]!=0)
									ChessValue[i,j]+=1;
							}
						}
						else
						{
							if(Attack[i,j]!=0)
							{
								if(!side)
								{
									if(chesstype==1)
										ChessValue[i,j]-=20;
									else
									{
                                        ChessValue[i, j] -= HalfValue * 2;
										if(Guard[i,j]!=0)
											ChessValue[i,j]+=HalfValue;
									}
								}
								else
								{
									if(chesstype==1)
										return 18888;
									else
									{
										ChessValue[i,j]-=HalfValue * 10;
										if(Guard[i,j]!=0)
											ChessValue[i,j]+=HalfValue * 9;
									}
								}
                                ChessValue[i, j] -= Attack[i, j];
							}
							else
							{
								if(Guard[i,j]!=0)
									ChessValue[i,j]+=1;
							}
						}
					}
				}
			int RedValue=0;
			int BlackValue=0;
			for(i=0;i<10;i++)
				for(j=0;j<9;j++)
				{
					chesstype=chess[i,j].chesstype;
					if(chess[i,j].chesstype!=0)
					{
						if(IsBlack(chesstype))
							BlackValue+=ChessValue[i,j];
						else
							RedValue+=ChessValue[i,j];
					}
				}           
                if (!side)
                    return BlackValue - RedValue;
                else
                    return RedValue - BlackValue;          
		}
Ejemplo n.º 28
0
 public Rules()
 {
     dad   = new DragAndDrop();
     chess = new Chess.Chess();
 }
Ejemplo n.º 29
0
    private async void Refresh()
    {
        if (isPlaying)
        {
            GameInfo info = await refBoard.GetCurrentGame();

            if (info.Statuse == "play")
            {
                Draw.SetActive(true);
            }
            if (info.Statuse == "wait")
            {
                g.SetActive(true);
                Draw.SetActive(false);
                v.SetActive(true);
            }
            else
            {
                g.SetActive(false);

                v.SetActive(false);
            }
            if (info.Statuse == "done")
            {
                isPlaying         = false;
                gameOverText.text = "Вы проиграли!!!";
                gameOverCanvas.SetActive(true);
                Draw.SetActive(false);
            }
            if (info.Statuse == "draw")
            {
                isPlaying         = false;
                gameOverText.text = "Ничья!!!";
                Draw.SetActive(false);
                gameOverCanvas.SetActive(true);
            }
            if (info.Statuse == "offerDraw")
            {
                offerDraw = true;
                Draw.SetActive(false);
                if (!youOfferDraw)
                {
                    AcceptDraw.SetActive(true);
                    DeclineDraw.SetActive(true);
                    DrawText.SetActive(true);
                }
            }
            else
            {
                youOfferDraw = false;
                offerDraw    = false;
                AcceptDraw.SetActive(false);
                DeclineDraw.SetActive(false);
                DrawText.SetActive(false);
            }
            chess = new Chess.Chess(info.FEN);
            if (yourColor == null)
            {
                yourColor = await refBoard.GetColorPlayer(info);

                for (int y = 0; y < 8; y++)
                {
                    for (int x = 0; x < 8; x++)
                    {
                        MarkSquare(x, y, false);
                    }
                }
            }

            if (dad.state != DragAndDrop.State.drag && flag)
            {
                ShowFigures();
            }
        }
    }
Ejemplo n.º 30
0
		private int PosibleMove(Chess[,] chess,bool side,int deep)
		{
			int x,y,chesstype,i,j;
			bool flag;
			MoveCount=0;
			for(i=0;i<10;i++)
				for(j=0;j<9;j++)
				{
					if(chess[i,j].chesstype!=0)
					{
						chesstype=chess[i,j].chesstype;
						if(side&&IsBlack(chesstype))
							continue;
						if(!side&&!IsBlack(chesstype))
							continue;
						switch(chesstype)
						{
							case 1://黑将							
							{
								for(y=0;y<3;y++)
									for(x=3;x<6;x++)
										if(CanMove(chess,j,i,x,y))
											AddMove(new Point(j,i),new Point(x,y),deep);
                                Point p=GetRedKingPos(chess);
                                if(CanMove(chess,j,i,p.X,p.Y))
                                    AddMove(new Point(j, i), p, deep);
								break;
							}
							case 8://红帅							
							{
								for(y=7;y<10;y++)
									for(x=3;x<6;x++)
										if(CanMove(chess,j,i,x,y))
											AddMove(new Point(j,i),new Point(x,y),deep);
                                Point p = GetBlackKingPos(chess);
                                if (CanMove(chess, j, i, p.X, p.Y))
                                    AddMove(new Point(j, i), p, deep);
								break;
							}
                            case 5://黑士
                            {
                                for (y = 0; y < 3; y++)
                                    for (x = 3; x < 6; x++)
                                        if (CanMove(chess, j, i, x, y))
                                            AddMove(new Point(j, i), new Point(x, y), deep);
                                break;
                            }
                            case 12://红仕
                            {
                                for (y = 7; y < 10; y++)
                                    for (x = 3; x < 6; x++)
                                        if (CanMove(chess, j, i, x, y))
                                            AddMove(new Point(j, i), new Point(x, y), deep);
                                break;
                            }
							case 6:
							case 13://象
							{
								x=j+2;
								y=i+2;
								if(x<9&&y<10&&CanMove(chess,i,y,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j+2;
								y=i-2;
								if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-2;
								y=i+2;
								if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-2;
								y=i-2;
								if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								break;
							}
							case 3:
							case 10://马
							{
								x=j+1;
								y=i+2;
								if(x<9&&y<10&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-1;
								y=i+2;
								if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j+1;
								y=i-2;
								if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-1;
								y=i-2;
								if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j+2;
								y=i+1;
								if(x<9&&y<10&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-2;
								y=i+1;
								if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j+2;
								y=i-1;
								if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								x=j-2;
								y=i-1;
								if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
									AddMove(new Point(j,i),new Point(x,y),deep);
								break;
							}
							case 2:
							case 9://車
							{
								x=j;
								y=i+1;
								while(y<10)
								{
									if(chess[y,x].chesstype==0)
										AddMove(new Point(j,i),new Point(x,y),deep);
									else 
									{
										if(!IsSameSide(chesstype,chess[y,x].chesstype))
											AddMove(new Point(j,i),new Point(x,y),deep);
										break;
									}									
									y++;
								}
								x=j;
								y=i-1;
								while(y>=0)
								{
									if(chess[y,x].chesstype==0)
										AddMove(new Point(j,i),new Point(x,y),deep);
									else 
									{
										if(!IsSameSide(chesstype,chess[y,x].chesstype))
											AddMove(new Point(j,i),new Point(x,y),deep);
										break;
									}									
									y--;
								}
								x=j+1;
								y=i;
								while(x<9)
								{
									if(chess[y,x].chesstype==0)
										AddMove(new Point(j,i),new Point(x,y),deep);
									else 
									{
										if(!IsSameSide(chesstype,chess[y,x].chesstype))
											AddMove(new Point(j,i),new Point(x,y),deep);
										break;
									}									
									x++;
								}
								x=j-1;
								y=i;
								while(x>=0)
								{
									if(chess[y,x].chesstype==0)
										AddMove(new Point(j,i),new Point(x,y),deep);
									else 
									{
										if(!IsSameSide(chesstype,chess[y,x].chesstype))
											AddMove(new Point(j,i),new Point(x,y),deep);
										break;
									}									
									x--;
								}
								break;
							}
							case 4:
							case 11://炮
							{
								flag=false;
								x=j;
								y=i+1;
								while(y<10)
								{
									if(chess[y,x].chesstype==0)
									{
										if(!flag)
											AddMove(new Point(j,i),new Point(x,y),deep);
									}
									else
									{
										if(!flag)
											flag=true;
										else
										{
											if(!IsSameSide(chesstype,chess[y,x].chesstype))
												AddMove(new Point(j,i),new Point(x,y),deep);
											break;
										}
									}
									y++;
								}
								flag=false;
								y=i-1;
								while(y>=0)
								{
									if(chess[y,x].chesstype==0)
									{
										if(!flag)
											AddMove(new Point(j,i),new Point(x,y),deep);
									}
									else
									{
										if(!flag)
											flag=true;
										else
										{
											if(!IsSameSide(chesstype,chess[y,x].chesstype))
												AddMove(new Point(j,i),new Point(x,y),deep);
											break;
										}
									}
									y--;
								}
								flag=false;
								x=j+1;
								y=i;
								while(x<9)
								{
									if(chess[y,x].chesstype==0)
									{
										if(!flag)
											AddMove(new Point(j,i),new Point(x,y),deep);
									}
									else
									{
										if(!flag)
											flag=true;
										else
										{
											if(!IsSameSide(chesstype,chess[y,x].chesstype))
												AddMove(new Point(j,i),new Point(x,y),deep);
											break;
										}
									}
									x++;
								}
								flag=false;
								x=j-1;
								while(x>0)
								{
									if(chess[y,x].chesstype==0)
									{
										if(!flag)
											AddMove(new Point(j,i),new Point(x,y),deep);
									}
									else
									{
										if(!flag)
											flag=true;
										else
										{
											if(!IsSameSide(chesstype,chess[y,x].chesstype))
												AddMove(new Point(j,i),new Point(x,y),deep);
											break;
										}
									}
									x--;
								}
								break;
							}
							case 7://黑卒
							{
								x=j;
								y=i+1;
								if(y<10&&!IsSameSide(chesstype,chess[y,x].chesstype))
									AddMove(new Point(j,i),new Point(x,y),deep);
								if(i>4)
								{
									x=j+1;
									y=i;
									if(x<9&&!IsSameSide(chesstype,chess[y,x].chesstype))
										AddMove(new Point(j,i),new Point(x,y),deep);
									x=j-1;
									if(x>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
										AddMove(new Point(j,i),new Point(x,y),deep);
								}
								break;
							}
							case 14:
							{
								x=j;
								y=i-1;
								if(y>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
									AddMove(new Point(j,i),new Point(x,y),deep);
								if(i<5)
								{
									x=j+1;
									y=i;
									if(x<9&&!IsSameSide(chesstype,chess[y,x].chesstype))
										AddMove(new Point(j,i),new Point(x,y),deep);
									x=j-1;
									if(x>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
										AddMove(new Point(j,i),new Point(x,y),deep);
								}
								break;
							}
							default:
								break;
						}
					}
				}
			return MoveCount;

		}
Ejemplo n.º 31
0
		private void GetRelation(Chess[,] chess,int i,int j)
		{
			int x,y,chesstype;
			bool flag;
			nRelation=0;
			chesstype=chess[i,j].chesstype;
			switch(chesstype)
			{
				case 1://黑将
				case 5://黑士
				{
					for(y=0;y<3;y++)
						for(x=3;x<6;x++)
							if(CanMove(chess,j,i,x,y))
								AddPoint(x,y);
					break;
				}
				case 8://红帅
				case 12://红仕
				{
					for(y=7;y<10;y++)
						for(x=3;x<6;x++)
							if(CanMove(chess,j,i,x,y))
								AddPoint(x,y);
					break;
				}
				case 6:
				case 13://象
				{
					x=j+2;
					y=i+2;
					if(x<9&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j+2;
					y=i-2;
					if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-2;
					y=i+2;
					if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-2;
					y=i-2;
					if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					break;
				}
				case 3:
				case 10://马
				{
					x=j+1;
					y=i+2;
					if(x<9&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-1;
					y=i+2;
					if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j+1;
					y=i-2;
					if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-1;
					y=i-2;
					if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j+2;
					y=i+1;
					if(x<9&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-2;
					y=i+1;
					if(x>=0&&y<10&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j+2;
					y=i-1;
					if(x<9&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					x=j-2;
					y=i-1;
					if(x>=0&&y>=0&&CanMove(chess,j,i,x,y))
						AddPoint(x,y);
					break;
				}
				case 2:
				case 9://車
				{
					x=j;
					y=i+1;
					while(y<10)
					{
						if(chess[y,x].chesstype==0)
							AddPoint(x,y);
						else 
						{
							if(!IsSameSide(chesstype,chess[y,x].chesstype))
								AddPoint(x,y);
							break;
						}									
						y++;
					}
					x=j;
					y=i-1;
					while(y>=0)
					{
						if(chess[y,x].chesstype==0)
							AddPoint(x,y);
						else 
						{
							if(!IsSameSide(chesstype,chess[y,x].chesstype))
								AddPoint(x,y);
							break;
						}									
						y--;
					}
					x=j+1;
					y=i;
					while(x<9)
					{
						if(chess[y,x].chesstype==0)
							AddPoint(x,y);
						else 
						{
							if(!IsSameSide(chesstype,chess[y,x].chesstype))
								AddPoint(x,y);
							break;
						}									
						x++;
					}
					x=j-1;
					y=i;
					while(x>=0)
					{
						if(chess[y,x].chesstype==0)
							AddPoint(x,y);
						else 
						{
							if(!IsSameSide(chesstype,chess[y,x].chesstype))
								AddPoint(x,y);
							break;
						}									
						x--;
					}
					break;
				}
				case 4:
				case 11://炮
				{
					flag=false;
					x=j;
					y=i+1;
					while(y<10)
					{
						if(chess[y,x].chesstype==0)
						{
							if(!flag)
								AddPoint(x,y);
						}
						else
						{
							if(!flag)
								flag=true;
							else
							{
								if(!IsSameSide(chesstype,chess[y,x].chesstype))
									AddPoint(x,y);
								break;
							}
						}
						y++;
					}
					flag=false;
					y=i-1;
					while(y>=0)
					{
						if(chess[y,x].chesstype==0)
						{
							if(!flag)
								AddPoint(x,y);
						}
						else
						{
							if(!flag)
								flag=true;
							else
							{
								if(!IsSameSide(chesstype,chess[y,x].chesstype))
									AddPoint(x,y);
								break;
							}
						}
						y--;
					}
					flag=false;
					x=j+1;
					y=i;
					while(x<9)
					{
						if(chess[y,x].chesstype==0)
						{
							if(!flag)
								AddPoint(x,y);
						}
						else
						{
							if(!flag)
								flag=true;
							else
							{
								if(!IsSameSide(chesstype,chess[y,x].chesstype))
									AddPoint(x,y);
								break;
							}
						}
						x++;
					}
					flag=false;
					x=j-1;
					while(x>0)
					{
						if(chess[y,x].chesstype==0)
						{
							if(!flag)
								AddPoint(x,y);
						}
						else
						{
							if(!flag)
								flag=true;
							else
							{
								if(!IsSameSide(chesstype,chess[y,x].chesstype))
									AddPoint(x,y);
								break;
							}
						}
						x--;
					}
					break;
				}
				case 7://黑卒
				{
					x=j;
					y=i+1;
					if(y<10&&!IsSameSide(chesstype,chess[y,x].chesstype))
						AddPoint(x,y);
					if(i>4)
					{
						x=j+1;
						y=i;
						if(x<9&&!IsSameSide(chesstype,chess[y,x].chesstype))
							AddPoint(x,y);
						x=j-1;
						if(x>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
							AddPoint(x,y);
					}
					break;
				}
				case 14://红兵
				{
					x=j;
					y=i-1;
					if(y>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
						AddPoint(x,y);
					if(i<5)
					{
						x=j+1;
						y=i;
						if(x<9&&!IsSameSide(chesstype,chess[y,x].chesstype))
							AddPoint(x,y);
						x=j-1;
						if(x>=0&&!IsSameSide(chesstype,chess[y,x].chesstype))
							AddPoint(x,y);
					}
					break;
				}
				default:
					break;
			}			
		}
Ejemplo n.º 32
0
        public override List <Point> GetMoves()
        {
            Point        curPoint;
            List <Point> moves = new List <Point>();

            Piece curPiece;
            //Piece[][] board = Chess.GetBoard().GetBoard();

            int row = this.loc.X,
                col = this.loc.Y;


            //4-directions
            //	0-> up-left
            //	1-> up-right
            //	2-> down-left
            //	3-> down-right
            bool[] stops = new bool[4];

            //double for-loop checks all 4 directions of movement (inner)
            //		at each (outer) iteration of increasing distance (1-4)

            //each iteration of mod is another tile of distance from current piece
            for (int mod = 1; mod <= 4; mod++)
            {
                //checks 4 directions
                for (int stop = 0; stop < 4; stop++)
                {
                    if (!stops[stop])
                    {
                        //converts iteration of inner loop to -1/1 for rows/cols
                        //	0 -> -1, -1
                        //	1 -> -1,  1
                        //	2 ->  1, -1
                        //	3 ->  1,  1
                        int dirModRow = (stop / 2 != 0) ? 1 : -1;
                        int dirModCol = (stop % 2 != 0) ? 1 : -1;

                        //Gets current point on map
                        curPoint = new Point(row + mod * dirModRow, col + mod * dirModCol);
                        if (InRange(curPoint))
                        {
                            //Gets piece at current point
                            curPiece = Chess.GetBoard().GetPiece(curPoint);

                            //Checks if this piece at current point
                            if (this.Beats(this, curPiece))
                            {
                                moves.Add(curPoint);
                                stops[stop] = (curPiece.GetColor() != ' ');
                            }
                            else
                            {
                                stops[stop] = true;
                            }
                        }
                        else
                        {
                            stops[stop] = true;
                        }
                    }
                }
            }
            return(moves);
        }
Ejemplo n.º 33
0
 private int SearchEngine1(Chess[,] chess, int alph, int beta, int deep)
 {
     int Count, i, score, chesstype,best;
     bool x;
     i = IsGameOver(chess, deep);
     if (i != 0)
         return i;
     if ((MaxDeep - deep) % 2 == 0)
         x = !side;
     else
         x = side;
     if (deep <= 0)
         return Caculate(chess, x);
     Count = PosibleMove(chess, x, deep);
     chesstype = MakeMove(movelist[deep, 0], chess);
     best = -SearchEngine1(chess, -alph, -beta, deep - 1);
     UnMakeMove(movelist[deep, 0], chesstype, chess);
     if (deep == MaxDeep)
     {
         BestMove.from = movelist[deep, 0].from;
         BestMove.to = movelist[deep, 0].to;
     }
     for (i = 1; i < Count; i++)
     {
         if (best < beta)
         {
             if (best > alph)
             {
                 alph = best;
             }
             chesstype = MakeMove(movelist[deep, i], chess);
             score = -SearchEngine1(chess, -alph - 1, -alph, deep - 1);
             if (score > beta)
             {
                 best = -SearchEngine1(chess, -beta, -score, deep - 1);
             }
             else if (score > best)
             {
                 best = score;
                 if (deep == MaxDeep)
                 {
                     BestMove.from = movelist[deep, i].from;
                     BestMove.to = movelist[deep, i].to;
                 }
             }
             UnMakeMove(movelist[deep, i], chesstype, chess);
         }
     }
     return best;
 }
Ejemplo n.º 34
0
    private void CreateGame()
    {
        GameInfo info = create.CreateOnce().Result;

        chess = new Chess.Chess(info.FEN);
    }
Ejemplo n.º 35
0
 private Point GetRedKingPos(Chess[,] chess)
 {
     int x, y;
     for (y = 7; y <= 9; y++)
     {
         for (x = 3; x < 6; x++)
             if (chess[y, x].chesstype == 1)
                 return new Point(x, y);
     }
     return new Point(0, 0);
 }
Ejemplo n.º 36
0
 private int SearchEngine(Chess[,] chess, int alph, int beta, int deep)
 {
     int Count, i, score, chesstype;
     bool x;
     i = IsGameOver(chess, deep);
     if (i != 0)
         return i;
      if ((MaxDeep - deep) % 2 == 0)
         x = !side;
     else
         x = side;
      if (deep <= 0)
          return Caculate(chess, x);
      Count = PosibleMove(chess, x, deep);
      for (i = 1; i < Count; i++)
      {
          chesstype = MakeMove(movelist[deep, i], chess);
          score = -SearchEngine(chess, -beta, -alph, deep - 1);
          UnMakeMove(movelist[deep, i], chesstype, chess);
          if (score > alph)
          {
              alph = score;
              if (deep == MaxDeep)
              {
                  BestMove.from = movelist[deep, i].from;
                  BestMove.to = movelist[deep, i].to;
              }
          }
          if (alph >= beta)
              break;
      }
      return alph;
 }
Ejemplo n.º 37
0
 public bool isOccupied(ChessPiece.PieceType? type = null, Chess.Game.Player? player = null)
 {
     return Piece != null && (type == null || Piece.GetType() == type) && (player == null || Piece.GetPlayer() == player);
 }
Ejemplo n.º 38
0
 private int MakeMove(Movelist move,Chess[,] chess)
 {
     int chesstype = chess[move.to.Y, move.to.X].chesstype;
     chess[move.to.Y, move.to.X].chesstype = chess[move.from.Y, move.from.X].chesstype;
     chess[move.from.Y, move.from.X].chesstype = 0;
     return chesstype;
 }
Ejemplo n.º 39
0
		private bool CanMove(Chess[,] chess,int FromX,int FromY,int ToX,int ToY)
		{
			int i,j;
			int Movechesstype,Targetchesstype;
			if(FromX==ToX&&FromY==ToY)
				return false;//没移动棋子
			Movechesstype=chess[FromY,FromX].chesstype;
			Targetchesstype=chess[ToY,ToX].chesstype;
			if(Targetchesstype!=0 && IsSameSide(Movechesstype,Targetchesstype))
				return false;//吃自己棋子
			switch(Movechesstype)
			{
				case 1://黑将
				{
					if(Targetchesstype==8)//是否死棋
					{
						if(FromX!=ToX)
							return false;//不在同一条线上
						for(i=FromY+1;i<ToY;i++)
							if(chess[i,FromX].chesstype!=0)
								return false;//中间隔有棋子
					}
					else
					{
						if(ToX<3||ToX>5||ToY>2)
							return false;//出九宫
						if(Math.Abs(FromX-ToX)+Math.Abs(FromY-ToY)>1)
							return false;//只能走一步直线
					}
					break;
				}
				case 8://红帅
				{
					if(Targetchesstype==1)//是否死棋
					{
						if(FromX!=ToX)
							return false;//不在同一条线上
						for(i=FromY-1;i>ToY;i--)
							if(chess[i,FromX].chesstype!=0)
								return false;//中间隔有棋子
					}
					else
					{
						if(ToX<3||ToX>5||ToY<7)
							return false;//出九宫
						if(Math.Abs(FromX-ToX)+Math.Abs(FromY-ToY)>1)
							return false;//只能走一步直线
					}
					break;
				}
				case 6://黑象
				{
					if(ToY>4)
						return false;//象不过河
					if(Math.Abs(FromX-ToX)!=2||Math.Abs(FromY-ToY)!=2)
						return false;//象走田字
					if(chess[(FromY+ToY)/2,(FromX+ToX)/2].chesstype!=0)
						return false;//象眼
					break;
				}
				case 13://红相
				{
					if(ToY<5)
						return false;//相不过河
					if(Math.Abs(FromX-ToX)!=2||Math.Abs(FromY-ToY)!=2)
						return false;//相走田字
					if(chess[(FromY+ToY)/2,(FromX+ToX)/2].chesstype!=0)
						return false;//相眼
					break;
				}
				case 5://黑士
				{
					if(ToX<3||ToX>5||ToY>2)
						return false;//出九宫
					if(Math.Abs(FromX-ToX)!=1||Math.Abs(FromY-ToY)!=1)
						return false;//士走斜线
					break;
				}
				case 12://红仕
				{
					if(ToX<3||ToX>5||ToY<7)
						return false;//出九宫
					if(Math.Abs(FromX-ToX)!=1||Math.Abs(FromY-ToY)!=1)
						return false;//仕走斜线
					break;
				}
				case 7://黑卒
				{
					if(FromY>ToY)
						return false;//卒不回头
					if(FromY<5&&FromY==ToY)
						return false;//过河前只向前
					if(ToY-FromY+Math.Abs(FromX-ToX)>1)
						return false;//只能走一步
					break;
				}
				case 14://红兵
				{
					if(FromY<ToY)
						return false;//兵不回头
					if(FromY>4&&FromY==ToY)
						return false;//过河前只向前
					if(FromY-ToY+Math.Abs(FromX-ToX)>1)
						return false;//只能走一步
					break;
				}
				case 2:
				case 9://車
				{
					if(FromX!=ToX&&FromY!=ToY)
						return false;//走直线
					if(FromY==ToY)//横向
					{
						if(FromX<ToX)//向右
						{
							for(i=FromX+1;i<ToX;i++)
								if(chess[FromY,i].chesstype!=0)
									return false;//中间有棋子
						}
						else//向左
						{
							for(i=FromX-1;i>ToX;i--)
								if(chess[FromY,i].chesstype!=0)
									return false;//中间有棋子
						}
					}
					else//纵向
					{
						if(FromY<ToY)//向下
						{
							for(i=FromY+1;i<ToY;i++)
								if(chess[i,FromX].chesstype!=0)
									return false;//中间有棋子
						}
						else//向上
						{
							for(i=FromY-1;i>ToY;i--)
								if(chess[i,FromX].chesstype!=0)
									return false;//中间有棋子
						}
					}
					break;
				}
				case 3:
				case 10://马
				{
					if(!((Math.Abs(FromX-ToX)==1&&Math.Abs(FromY-ToY)==2)||(Math.Abs(FromX-ToX)==2&&Math.Abs(FromY-ToY)==1)))
						return false;//马走日字
					if(FromX-ToX==2)//左
					{
						i=FromY;
						j=FromX-1;
					}
					else if(ToX-FromX==2)//右
					{
						i=FromY;
						j=FromX+1;
					}
					else if(FromY-ToY==2)//上
					{
						i=FromY-1;
						j=FromX;
					}
					else//下
					{
						i=FromY+1;
						j=FromX;
					}
					if(chess[i,j].chesstype!=0)
						return false;//马脚
					break;
				}
				case 4:
				case 11://炮
				{
					if(FromX!=ToX&&FromY!=ToY)
						return false;//走直线
					if(chess[ToY,ToX].chesstype!=0)//吃棋子
					{
						
						int count=0;
						if(FromY==ToY)//横向
						{
							if(FromX<ToX)//向右
							{
								for(i=FromX+1;i<ToX;i++)
									if(chess[FromY,i].chesstype!=0)
										count++;
								if(count!=1)
									return false;//中间没棋子
							}
							else//向左
							{
								for(i=FromX-1;i>ToX;i--)
									if(chess[FromY,i].chesstype!=0)
										count++;
								if(count!=1)
									return false;//中间没棋子
							}
						}
						else//纵向
						{							
							if(FromY<ToY)//向下
							{
								for(i=FromY+1;i<ToY;i++)
									if(chess[i,FromX].chesstype!=0)
										count++;
								if(count!=1)
									return false;//中间没棋子
							}
							else//向上
							{
								for(i=FromY-1;i>ToY;i--)
									if(chess[i,FromX].chesstype!=0)
										count++;
								if(count!=1)
									return false;//中间没棋子
							}
						}
					}
					else//不吃棋子
					{
						if(FromY==ToY)//横向
						{
							if(FromX<ToX)//向右
							{
								for(i=FromX+1;i<ToX;i++)
									if(chess[FromY,i].chesstype!=0)
										return false;//中间有棋子
							}
							else//向左
							{
								for(i=FromX-1;i>ToX;i--)
									if(chess[FromY,i].chesstype!=0)
										return false;//中间有棋子
							}
						}
						else//纵向
						{
							if(FromY<ToY)//向下
							{
								for(i=FromY+1;i<ToY;i++)
									if(chess[i,FromX].chesstype!=0)
										return false;//中间有棋子
							}
							else//向上
							{
								for(i=FromY-1;i>ToY;i--)
									if(chess[i,FromX].chesstype!=0)
										return false;//中间有棋子
							}
						}
					}
					break;
				}
				default:
					return false;				
			}
			return true;
		}
Ejemplo n.º 40
0
		private int GetBingValue(Chess[,] chess,int x,int y)
		{
			if(chess[y,x].chesstype==7)
				return Additional1[y,x];
			if(chess[y,x].chesstype==14)
				return Additional2[y,x];
			return 0;
		}
Ejemplo n.º 41
0
		private bool IsSelect(Chess[,]chess)
		{
			int i,j;
            for (i = 0; i < 10; i++)
            {
                for (j = 0; j < 9; j++)
                {
                    if (chess[i, j].select)
                    {
                        p = new Point(j, i);
                        return true;
                    }
                }
            }
            return false;
		}
Ejemplo n.º 42
0
 public Pawn(Chess.Game.Player color)
 {
     base.player = color;
 }
Ejemplo n.º 43
0
 public void InsertNewPiece(char coluna, int linha, Peca peca)
 {
     Chess.InsertPiece(peca, new PositionChess(coluna, linha).ToPosition());
     Pieces.Add(peca);
 }