Exemple #1
0
        public void CalcNextAction(ReversiBoard board)
        {
            var puttables = board.ListupPuttables(this.mark);

            if (puttables.Count == 0)
            {
                this.nextAction = ReversiAction.Pass();
                return;
            }
            Random rd = new Random();
            var    p  = puttables [rd.Next(puttables.Count)];

            this.nextAction = ReversiAction.PutAt(p.X, p.Y);
        }
Exemple #2
0
        /// <summary>
        /// (x,y) に Mark をおいたときにひっくり返る座標のリストを返す。
        /// </summary>
        /// <returns>The when put.</returns>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        /// <param name="mark">Mark.</param>
        public List <Pos> ReverseWhenPut(int x, int y, ReversiMark mark)
        {
            List <Pos> poses = new List <Pos>();
            var        dx    = new int[] { -1, 0, 1, -1, 1, -1, 0, 1 };
            var        dy    = new int[] { -1, -1, -1, 0, 0, 1, 1, 1 };

            // 8近傍を探索
            for (int i = 0; i < dx.Length; i++)
            {
                if (!ReversiBoard.IsIn(x + dx [i], y + dy [i]))
                {
                    continue;
                }
                // 隣が反対の色であることが重要
                if ((int)this.At(x + dx [i], y + dy [i]) == -(int)mark)
                {
                    List <Pos> candidates = new List <Pos> ();
                    bool       flag       = false;         // その方向にひっくり返せるかのフラグ
                    for (int j = 1; true; j++)
                    {
                        var x2 = x + dx [i] * j;
                        var y2 = y + dy [i] * j;
                        if (!ReversiBoard.IsIn(x2, y2))
                        {
                            break;
                        }

                        if ((int)this.At(x2, y2) == -(int)mark)
                        {
                            candidates.Add(new Pos(x2, y2));
                        }
                        else if (this.At(x2, y2) == mark)
                        {
                            flag = true;
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                    if (flag)
                    {
                        poses.AddRange(candidates);
                    }
                }
            }
            return(poses);
        }
Exemple #3
0
 /// <summary>
 /// (x, y) に mark を置けるならtrueです
 /// </summary>
 /// <returns><c>true</c> if this instance is puttable at the specified x y mark; otherwise, <c>false</c>.</returns>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 /// <param name="mark">Mark.</param>
 public bool IsPuttableAt(int x, int y, ReversiMark mark)
 {
     if (!ReversiBoard.IsIn(x, y))
     {
         return(false);
     }
     if (this.At(x, y) != ReversiMark.EMPTY)
     {
         return(false);
     }
     if (this.ReverseWhenPut(x, y, mark).Count == 0)
     {
         return(false);
     }
     return(true);
 }
Exemple #4
0
        public ReversiManager(ReversiPlayer p1, ReversiPlayer p2)
        {
            this.board   = new ReversiBoard();
            this.players = new ReversiPlayer[] { p1, p2 };
            this.turn    = 0;

            // check marks
            if (p1.GetMark() == ReversiMark.EMPTY)
            {
                throw new ReversiException("player mark cannot be empty");
            }
            if ((int)p1.GetMark() * (-1) != (int)p2.GetMark())
            {
                throw new ReversiException("player marks are invalid");
            }
        }
Exemple #5
0
 public void CalcNextAction(ReversiBoard board)
 {
 }
Exemple #6
0
 /// <summary>
 /// (x, y) の状態を返しますよ
 /// </summary>
 /// <param name="x">The x coordinate.</param>
 /// <param name="y">The y coordinate.</param>
 public ReversiMark At(int x, int y)
 {
     ReversiBoard.AssertIsIn(x, y);
     return(this.board [size * y + x]);
 }
Exemple #7
0
 /// <summary>
 /// (x,y) を mark にする。ひっくり返すとかしません
 /// </summary>
 /// <param name="x">x座標( 0 <= x <= 7 )</param>
 /// <param name="y">y座標( 0 <= x <= 7 )</param>
 /// <param name="mark">Mark.</param>
 public void Set(int x, int y, ReversiMark mark)
 {
     ReversiBoard.AssertIsIn(x, y);
     this.board [size * y + x] = mark;
 }