ChineseChess.Core/Chessboard.cs

(开头部分) 7KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.Linq;

namespace ChineseChess.Core
{
    public class Chessboard
    {
        private readonly Stack<ChessMove> Moves = new Stack<ChessMove>();

        private readonly List<Chessman> AlivingChessman = new List<Chessman>(32);

        public event EventHandler<ChessmanMovedEventArgs> ChessmanMovedEvent;

        private void OnChessmanMoved(Chessman chessman, Chessman chessmanKilled)
            => ChessmanMovedEvent?.Invoke(this, new ChessmanMovedEventArgs(chessman, chessmanKilled));

        public Chessman GetChessmanByPos(ChessboardPosition position)
            => AlivingChessman.FirstOrDefault(c => c.Position == position);

        public IEnumerable<Chessman> GetChessmenByType(ChessType type, ChessCamp camp)
            => AlivingChessman.Where(chess => chess.Type == type && chess.Camp == camp);

        public IEnumerable<Chessman> GetChessmen() => AlivingChessman;

        public IEnumerable<ChessMove> GetMoves() => Moves;

        public void ResetChessboard()
        {
            AlivingChessman.Clear();
            AlivingChessman.Add(new Chessman(ChessType.King     , ChessCamp.Red, new ChessboardPosition(4, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Red, new ChessboardPosition(3, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Red, new ChessboardPosition(5, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Knights  , ChessCamp.Red, new ChessboardPosition(2, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Knights  , ChessCamp.Red, new ChessboardPosition(6, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Red, new ChessboardPosition(1, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Red, new ChessboardPosition(7, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Rooks    , ChessCamp.Red, new ChessboardPosition(0, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Rooks    , ChessCamp.Red, new ChessboardPosition(8, 0)));
            AlivingChessman.Add(new Chessman(ChessType.Cannons  , ChessCamp.Red, new ChessboardPosition(1, 2)));
            AlivingChessman.Add(new Chessman(ChessType.Cannons  , ChessCamp.Red, new ChessboardPosition(7, 2)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Red, new ChessboardPosition(0, 3)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Red, new ChessboardPosition(2, 3)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Red, new ChessboardPosition(4, 3)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Red, new ChessboardPosition(6, 3)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Red, new ChessboardPosition(8, 3)));

            AlivingChessman.Add(new Chessman(ChessType.King     , ChessCamp.Black, new ChessboardPosition(4, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Black, new ChessboardPosition(3, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Mandarins, ChessCamp.Black, new ChessboardPosition(5, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Knights  , ChessCamp.Black, new ChessboardPosition(2, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Knights  , ChessCamp.Black, new ChessboardPosition(6, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Black, new ChessboardPosition(1, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Elephants, ChessCamp.Black, new ChessboardPosition(7, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Rooks    , ChessCamp.Black, new ChessboardPosition(0, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Rooks    , ChessCamp.Black, new ChessboardPosition(8, 9)));
            AlivingChessman.Add(new Chessman(ChessType.Cannons  , ChessCamp.Black, new ChessboardPosition(1, 7)));
            AlivingChessman.Add(new Chessman(ChessType.Cannons  , ChessCamp.Black, new ChessboardPosition(7, 7)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Black, new ChessboardPosition(0, 6)));
            AlivingChessman.Add(new Chessman(ChessType.Pawns    , ChessCamp.Black, new ChessboardPosition(2, 6)));
后面还有 85 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。