示例#1
0
 public override bool AttackTarget(Figure f)
 {
     if (_player == Player.White)
     {
         if ((((X + 1) & (int.MaxValue - 7)) == 0) &&
                ((Y + 1) & (int.MaxValue - 7)) == 0)
         {
             if (ReferenceEquals(_board[((X + 1) << 3) + Y + 1], f)) return true;
         }
         if ((((X + 1) & (int.MaxValue - 7)) == 0) &&
                ((Y - 1) & (int.MaxValue - 7)) == 0)
         {
             if (ReferenceEquals(_board[((X + 1) << 3) + Y - 1], f)) return true;
         }
     }
     else
     {
         if ((((X - 1) & (int.MaxValue - 7)) == 0) &&
                ((Y + 1) & (int.MaxValue - 7)) == 0)
         {
             if (ReferenceEquals(_board[((X - 1) << 3) + Y + 1], f)) return true;
         }
         if ((((X - 1) & (int.MaxValue - 7)) == 0) &&
                ((Y - 1) & (int.MaxValue - 7)) == 0)
         {
             if (_board[((X - 1) << 3) + Y - 1] == f) return true;
         }
     }
     return false;
 }
示例#2
0
 public Game(Board board)
 {
     _board = board;
     Player = Player.White;
     for (var i = 0; i < 8; i++)
         for (var j = 0; j < 8; j++)
             if (_board[(i << 3) + j] is King)
             {
                 if (_board[(i << 3) + j].Player == Player.White)
                     _whiteKing = _board[(i << 3) + j];
                 else _blackKing = _board[(i << 3) + j];
             }
 }
示例#3
0
 static void PrintBoard(Figure[] board)
 {
     Console.WriteLine("  A B C D E F G H");
     Console.WriteLine();
     for (var i=0; i<8; i++)
     {
         Console.Write((i + 1).ToString() + " ");
         for (var j=0; j<8; j++)
         {
             if (board[(i<<3) + j] == null) Console.Write(". ");
             else Console.Write(board[(i<<3) + j].ToString()+" ");
         }
         Console.WriteLine();
     }
 }
示例#4
0
 public override bool AttackTarget(Figure f)
 {
     var t = (f.X << 3) + f.Y;
     var p = pSteps[(X << 3) + Y];
     if (!p.Attack.ContainsKey(t)) return false;
     var r = p.Attack[t];
     var cur = p.Rays[r];
     while (cur != null)
     {
         if (cur.step.ToX == f.X && cur.step.ToY == f.Y) return true;
         if (_board[(cur.step.ToX << 3) + cur.step.ToY] != null) return false;
         cur = cur.NextRay;
     }
     return false;
 }
示例#5
0
 public override bool AttackTarget(Figure f)
 {
     if (pSteps[(X << 3) + Y].Contains((f.X << 3) + f.Y)) return true;
     return false;
 }
示例#6
0
 public bool IsEnemy(Figure f)
 {
     return f._player != _player;
 }
示例#7
0
 public abstract bool AttackTarget(Figure f);
示例#8
0
 private int countAtacksToFigure(Figure f)
 {
     var res = 0;
     foreach (var x in _board.Figures)
     {
         if (x == null || x.Player == f.Player) continue;
         if (x.AttackTarget(f)) res++;
     }
     return res;
 }