static void Main(string[] args) { Random random = new Random(); Chess chess = new Chess(); List <string> list; while (true) { Console.WriteLine(chess.fen); list = chess.GetAllMoves(); 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); } }
static void Main(string[] args) { Random random = new Random(); Chess chess = new Chess(); // ("rnbqkbnr/pp1111pp/8/8/8/8/PP11111P/RNBQKBNR w KQkq - 0 1"); List <string> listMoves; while (true) { listMoves = chess.GetAllMoves(); Console.WriteLine(chess.fen); Print(ChessToASCII(chess)); Console.WriteLine(chess.isCheck() ? "CHECK" : "-"); foreach (string moves in listMoves) { Console.Write(moves + "\t"); } Console.WriteLine(); Console.Write("> "); string move = Console.ReadLine(); if (move == "q") { break; } if (move == "") { move = listMoves[random.Next(listMoves.Count)]; } chess = chess.Move(move); } }
static int NextMoves(int step, Chess chess) { if (step == 0) return 1; int count = 0; foreach (string moves in chess.YieldValidMoves()) count += NextMoves((step - 1), chess.Move(moves)); return count; }
static int NextMoves(int step, Chess chess) { if (step == 0) { return(1); } int count = 0; foreach (string moves in chess.YieldValidMoves()) { count += NextMoves((step - 1), chess.Move(moves)); } return(count); }
static void Main(string[] args) { Chess chess = new Chess(); while (true) { Console.WriteLine(chess.fen); Print(ChessToAscii(chess)); string move = Console.ReadLine(); if (move == "") { break; } chess = chess.Move(move); } }
static void Main(string[] args) { var chess = new Chess("rnbqkbnr/p2pp1pp/8/1pp2p2/3P1P2/3B4/PP1P1PPP/RNBQK1NR w KQkq - 0 1"); var nums = Extentions.ValidMoves(3, chess); Console.WriteLine(nums); // return; while (true) { //Console.WriteLine(chess.fen); Extentions.Print(Extentions.ChessToAscii(chess)); var move = Console.ReadLine(); if (move == string.Empty) { break; } chess = chess.Move(move); } }
static void Main(string[] args) { Chess chess = new Chess("rnbqkbnr/1p1111p1/8/8/8/8/1P1111P1/RNBQKBNR w KQkq - 0 0"); while (true) { Console.WriteLine(chess.GetFen()); foreach (string moves in chess.GetAllMoves()) { Console.WriteLine(moves + "\t"); } Console.WriteLine(chess.IsCheck()?"CHECK!":""); Console.WriteLine(); Console.WriteLine(ChessToAscii(chess)); Console.Write("> "); string move = Console.ReadLine(); if (!string.IsNullOrWhiteSpace(move)) { chess = chess.Move(move); } } }
public static void Main(string[] args) { Chess chess = new Chess(); // Console.WriteLine(NextMoves(5, chess)); // Console.ReadKey(); // return; while (true) { Console.WriteLine(chess.fen); Print(ChessToAscii(chess)); foreach (string moves in chess.YieldValidMoves()) { Console.WriteLine(moves); } string move = Console.ReadLine(); if (move == "") { break; } chess = chess.Move(move); } }
//鼠标点击事件 private void pbChessboard_MouseClick(object sender, MouseEventArgs e) { if (!isBegin) { return; } //取出点击位置的棋子 //由坐标转换为下标 int x = (e.X - 10) / GameControl.chessSize; int y = (e.Y - 10) / GameControl.chessSize; //MessageBox.Show("x:"+x+"y:"+y); Chess chess = GameControl.chessArray[y, x]; //表示点击位置有棋子 if (chess != null) { //没有篮框棋子 if (currentChess == null) { //选子 //如果该红方走 并且选的子就是红方 if (isTurn == 1 && chess.ChessCamp == Camp.红方) { //1、把点击这个棋子赋值给篮框棋子 currentChess = chess; //2、画框 currentChess.Choice(GameControl.img); } //如果该黑方走 并且选的子就是黑方 else if (isTurn == 0 && chess.ChessCamp == Camp.黑方) { //1、把点击这个棋子赋值给篮框棋子 currentChess = chess; //2、画框 currentChess.Choice(GameControl.img); } Music.play("选子"); } //有篮框棋子 else { //换子 吃子 //篮框棋子阵营等于选择(点击)棋子阵营 if (currentChess.ChessCamp == chess.ChessCamp) { //选子 //1、先抹掉篮框的棋子 就是重新画阵营 Frush(); //2、在新位置重写画一个篮框 currentChess = chess; currentChess.Choice(GameControl.img); Music.play("换子"); } else { //x y点击位置的下标 if (!currentChess.Move(x, y)) { return; } //计算篮框棋子在原来数组中的下标位置 int xLan = (currentChess.ChessPoint.X - 10) / GameControl.chessSize; int yLan = (currentChess.ChessPoint.Y - 10) / GameControl.chessSize; //吃子 //1、改变篮框棋子的坐标位置 currentChess.ChessPoint = chess.ChessPoint; //2、改变篮框棋子的数组中的位置也要改变 GameControl.chessArray[y, x] = currentChess; //3、篮框棋子在数组中原来的位置恢复为null GameControl.chessArray[yLan, xLan] = null; //刷新 Frush(); //判断吃掉的棋子是不是boss if (GameControl.IsWin(chess)) { MessageBox.Show("游戏结束!"); isBegin = false; GameControl.ClearArrays(); return; } else { //换人 TurnNext(); } Music.play("吃子"); } } } //表示点击位置没有棋子 (走棋) else { if (currentChess == null) //篮框棋子为空 { return; } else if (!currentChess.Move(x, y)) { return; } else { //有篮框 又可以动 //计算篮框棋子在原来数组中的下标位置 int xLan = (currentChess.ChessPoint.X - 10) / GameControl.chessSize; int yLan = (currentChess.ChessPoint.Y - 10) / GameControl.chessSize; //移动 //1、让篮框棋子移动到指定的位置 该坐标 int xDianJi = 10 + x * 57; int yDianJi = 10 + y * 57; currentChess.ChessPoint = new Point(xDianJi, yDianJi); //2、改变篮框棋子在数组中的位置 GameControl.chessArray[y, x] = currentChess; //3、篮框棋子在数组中的原来位置改为null GameControl.chessArray[yLan, xLan] = null; //刷新 Frush(); //换人 TurnNext(); Music.play("移动"); } } this.pbChessboard.Image = GameControl.img; }