コード例 #1
0
ファイル: ReversiPanel.cs プロジェクト: ufcpp/UfcppSample
			public void SetColor(ReversiColor color)
			{
				Image img = parent.none_image;
				if(color == ReversiColor.Black) img = parent.black_image;
				if(color == ReversiColor.White) img = parent.white_image;
				if(this.Image != img) this.Image = img;
			}
コード例 #2
0
        /// <summary>
        /// ゲーム開始の処理
        /// </summary>
        private void GameStart()
        {
            this.board = new ReversiBoard(option.board_width, option.board_height);

            this.panel.Board = this.board;

            this.ClientSize = new Size(this.panel.Width, this.panel.Height + this.status_bar.Height);

            this.phase = ReversiColor.Black;
            ShowPhaseMessage();
        }
コード例 #3
0
        /// <summary>
        /// 座標(x,y)にコマをおけるかどうか、1ライン分調べる
        /// (Checkメソッドで利用する)
        /// <param name="x">調べる場所のx座標</param>
        /// <param name="y">調べる場所のy座標</param>
        /// <returns>置けるかどうか</returns>
        /// </summary>
        private bool CheckLine(int x, int y, int dx, int dy, ReversiColor color)
        {
            int          i, j;
            ReversiColor inverse_color = InverseColor(color);

            for (i = x + dx, j = y + dy; this.board[i, j] == inverse_color; i += dx, j += dy)
            {
                ;
            }
            return(!(i == x + dx && j == y + dy) && this.board[i, j] == color);
        }
コード例 #4
0
 /// <summary>
 /// 駒の色と逆の色を返す
 /// </summary>
 /// <param name="color">駒の色</param>
 /// <returns>逆の色</returns>
 static public ReversiColor InverseColor(ReversiColor color)
 {
     if (color == ReversiColor.Black)
     {
         return(ReversiColor.White);
     }
     if (color == ReversiColor.White)
     {
         return(ReversiColor.Black);
     }
     return(color);
 }
コード例 #5
0
        //=========================================================
        // public methods

        /// <summary>
        /// 座標(x,y)にコマをおけるかどうかを調べる
        /// <param name="x">調べる場所のx座標 0〜width-1</param>
        /// <param name="y">調べる場所のy座標 0〜width-1</param>
        /// <returns>置けるかどうか</returns>
        /// </summary>
        public bool Check(int x, int y, ReversiColor color)
        {
            ++x; ++y;
            return(this.board[x, y] == ReversiColor.None &&
                   (CheckLine(x, y, -1, 0, color) ||              //左
                    CheckLine(x, y, 1, 0, color) ||                //右
                    CheckLine(x, y, 0, -1, color) ||               //上
                    CheckLine(x, y, 0, 1, color) ||                //下
                    CheckLine(x, y, -1, -1, color) ||              //左上
                    CheckLine(x, y, 1, -1, color) ||               //右上
                    CheckLine(x, y, -1, 1, color) ||               //左下
                    CheckLine(x, y, 1, 1, color)));                //右上
        }
コード例 #6
0
        /// <summary>
        /// 盤面に置けるますがあるかどうかを調べる
        /// </summary>
        /// <returns>置けるますが存在するかどうか</returns>
        public bool CheckAll(ReversiColor color)
        {
            for (int x = 1; x <= this.width; ++x)
            {
                for (int y = 1; y <= this.height; ++y)
                {
                    if (Check(x, y, color))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
コード例 #7
0
        public int GetScore(ReversiColor color)
        {
            int black, white;

            this.CountUp(out black, out white);
            if (color == ReversiColor.Black)
            {
                return(black);
            }
            if (color == ReversiColor.White)
            {
                return(white);
            }
            return(0);
        }
コード例 #8
0
 public bool Pass()
 {
     for (int i = 0; i < Board.GetLength(0); i++)
     {
         for (int j = 0; j < Board.GetLength(1); j++)
         {
             if (MovePossible(i, j))
             {
                 return(false);
             }
         }
     }
     ColorTurn = ColorTurn == ReversiColor.Black ? ReversiColor.White : ReversiColor.Black;
     return(true);
 }
コード例 #9
0
        /// <summary>
        /// 対人戦時、セル(x,y)がクリックされたときの処理
        /// </summary>
        protected void OnCellClick(int x, int y)
        {
            if (!this.board.Check(x, y, this.phase))
            {
                return;
            }

            this.board[x, y] = this.phase;
            this.panel.UpdateBoard();
            this.phase = ReversiBoard.InverseColor(this.phase);
            ShowPhaseMessage();
            if (!this.board.CheckAll(this.phase))
            {
                GameSet();
            }
        }
コード例 #10
0
        //=========================================================
        // private methods

        /// <summary>
        /// 盤面の更新を1ラインずつ行う
        /// <param name="x">置く場所のx座標</param>
        /// <param name="y">置く場所のy座標</param>
        /// <param name="color">置く駒の色</param>
        /// </summary>
        private void UpdateLine(int x, int y, int dx, int dy, ReversiColor color)
        {
            int          i, j;
            ReversiColor inverse_color = InverseColor(color);

            for (i = x + dx, j = y + dy; this.board[i, j] == inverse_color; i += dx, j += dy)
            {
                ;
            }
            if (!(i == x + dx && j == y + dy) && this.board[i, j] == color)
            {
                for (i -= dx, j -= dy; !(i == x && j == y); i -= dx, j -= dy)
                {
                    this.board[i, j] = color;
                }
            }
        }
コード例 #11
0
            public void SetColor(ReversiColor color)
            {
                Image img = parent.none_image;

                if (color == ReversiColor.Black)
                {
                    img = parent.black_image;
                }
                if (color == ReversiColor.White)
                {
                    img = parent.white_image;
                }
                if (this.Image != img)
                {
                    this.Image = img;
                }
            }
コード例 #12
0
        public bool PerformMove(int rowMove, int columnMove)
        {
            if (!MovePossible(rowMove, columnMove))
            {
                return(false);
            }
            Board[rowMove, columnMove] = ColorTurn;
            List <Cordinate> cordinatesToFlip = new List <Cordinate>();
            bool             succes           = false;
            var opposingColor = ColorTurn == ReversiColor.Black ? ReversiColor.White : ReversiColor.Black;

            for (int i = 0; i < DirX.Length; i++)
            {
                int y = rowMove, x = columnMove;
                for (int j = 0; j < Board.GetLength(0); j++)
                {
                    y += DirY[i];
                    x += DirX[i];
                    if (!WithinBoard(y, x))
                    {
                        break;
                    }
                    if ((Board[y, x].Equals(ReversiColor.None)))
                    {
                        continue;
                    }
                    if (Board[y, x].Equals(opposingColor))
                    {
                        cordinatesToFlip.Add(new Cordinate(y, x));
                    }
                    if (!Board[y, x].Equals(ColorTurn))
                    {
                        continue;
                    }
                    foreach (var cordinate in cordinatesToFlip)
                    {
                        Board[cordinate.Y, cordinate.X] = ColorTurn;
                        succes = true;
                    }
                }
            }

            ColorTurn = opposingColor;
            return(succes);
        }
コード例 #13
0
        public bool SurroundingTilesCheck(int rowMove, int columnMove)
        {
            var surroundingTiles = new ReversiColor[8];

            //Up Tile
            surroundingTiles[0] = getTileColor(rowMove - 1, columnMove);
            //Left Tile
            surroundingTiles[1] = getTileColor(rowMove, columnMove - 1);
            //Right Tile
            surroundingTiles[2] = getTileColor(rowMove, columnMove + 1);
            //Down Tile
            surroundingTiles[3] = getTileColor(rowMove + 1, columnMove);

            //LeftUp tile
            surroundingTiles[4] = getTileColor(rowMove - 1, columnMove - 1);
            //RightUp tile
            surroundingTiles[5] = getTileColor(rowMove - 1, columnMove + 1);
            //LeftDown
            surroundingTiles[6] = getTileColor(rowMove + 1, columnMove - 1);
            //RightDown
            surroundingTiles[7] = getTileColor(rowMove + 1, columnMove + 1);


            if (surroundingTiles.All(st => st.Equals(ReversiColor.None)))
            {
                return(true);
            }
            for (int i = 0; i < 4; i++)
            {
                if (surroundingTiles[i].Equals(ColorTurn))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #14
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		public int GetScore(ReversiColor color)
		{
			int black, white;
			this.CountUp(out black, out white);
			if(color == ReversiColor.Black) return black;
			if(color == ReversiColor.White) return white;
			return 0;
		}
コード例 #15
0
ファイル: ReversiForm.cs プロジェクト: ufcpp/UfcppSample
		/// <summary>
		/// 対人戦時、セル(x,y)がクリックされたときの処理
		/// </summary>
		protected void OnCellClick(int x, int y)
		{
			if(!this.board.Check(x, y, this.phase))
			{
				return;
			}

			this.board[x, y] = this.phase;
			this.panel.UpdateBoard();
			this.phase = ReversiBoard.InverseColor(this.phase);
			ShowPhaseMessage();
			if(!this.board.CheckAll(this.phase))
			{
				GameSet();
			}
		}
コード例 #16
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		//=========================================================
		// public methods

		/// <summary>
		/// 座標(x,y)にコマをおけるかどうかを調べる
		/// <param name="x">調べる場所のx座標 0〜width-1</param>
		/// <param name="y">調べる場所のy座標 0〜width-1</param>
		/// <returns>置けるかどうか</returns>
		/// </summary>
		public bool Check(int x, int y, ReversiColor color)
		{
			++x; ++y;
			return this.board[x,y] == ReversiColor.None &&
				( CheckLine(x, y, -1,  0, color)  //左
				|| CheckLine(x, y,  1,  0, color)  //右
				|| CheckLine(x, y,  0, -1, color)  //上
				|| CheckLine(x, y,  0,  1, color)  //下
				|| CheckLine(x, y, -1, -1, color)  //左上
				|| CheckLine(x, y,  1, -1, color)  //右上
				|| CheckLine(x, y, -1,  1, color)  //左下
				|| CheckLine(x, y,  1,  1, color));//右上
		}
コード例 #17
0
ファイル: ReversiForm.cs プロジェクト: ufcpp/UfcppSample
		/// <summary>
		/// ゲーム開始の処理
		/// </summary>
		private void GameStart()
		{
			this.board = new ReversiBoard(option.board_width, option.board_height);

			this.panel.Board = this.board;

			this.ClientSize = new Size(this.panel.Width, this.panel.Height + this.status_bar.Height);

			this.phase = ReversiColor.Black;
			ShowPhaseMessage();
		}
コード例 #18
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		/// <summary>
		/// 盤面に置けるますがあるかどうかを調べる
		/// </summary>
		/// <returns>置けるますが存在するかどうか</returns>
		public bool CheckAll(ReversiColor color)
		{
			for(int x=1; x<=this.width; ++x)
				for(int y=1; y<=this.height; ++y)
					if(Check(x,y, color)) return true;

			return false;
		}
コード例 #19
0
        private bool LineContainsSameColor(int sY, int eY, int sX, int eX, Direction dir,
                                           ReversiColor colorTurn)
        {
            switch (dir)
            {
                #region StraightLines

            case Direction.Left:
                for (int i = sX; i >= eX; i--)
                {
                    if (Board[sY, i].Equals(colorTurn))
                    {
                        return(true);
                    }
                }

                break;

            case Direction.Right:
                for (int i = sX; i <= eX; i++)
                {
                    if (Board[sY, i].Equals(colorTurn))
                    {
                        return(true);
                    }
                }

                break;

            case Direction.Up:
                for (int i = sY; i >= eY; i--)
                {
                    if (Board[i, sX].Equals(colorTurn))
                    {
                        return(true);
                    }
                }

                break;

            case Direction.Down:
                for (int i = sY; i <= eY; i++)
                {
                    if (Board[i, sX].Equals(colorTurn))
                    {
                        return(true);
                    }
                }

                break;

                #endregion

                #region DiagonalLines

            case Direction.LeftUp:
                while (sY >= eY && sX >= eX)
                {
                    if (Board[sY, sX].Equals(colorTurn))
                    {
                        return(true);
                    }

                    sY -= 1;
                    sX -= 1;
                }

                break;

            case Direction.RightUp:
                while (sY >= eY && sX <= eX)
                {
                    if (Board[sY, sX].Equals(colorTurn))
                    {
                        return(true);
                    }

                    sY -= 1;
                    sX += 1;
                }

                break;

            case Direction.LeftDown:
                while (sY <= eY && sX >= eX)
                {
                    if (Board[sY, sX].Equals(colorTurn))
                    {
                        return(true);
                    }

                    sY += 1;
                    sX -= 1;
                }

                break;

            case Direction.RightDown:
                while (sY <= eY && sX <= eX)
                {
                    if (Board[sY, sX].Equals(colorTurn))
                    {
                        return(true);
                    }

                    sY += 1;
                    sX += 1;
                }

                break;

                #endregion

            default:
                throw new ArgumentOutOfRangeException(nameof(dir), dir, null);
            }

            return(false);
        }
コード例 #20
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		/// <summary>
		/// 座標(x,y)にコマをおけるかどうか、1ライン分調べる
		/// (Checkメソッドで利用する)
		/// <param name="x">調べる場所のx座標</param>
		/// <param name="y">調べる場所のy座標</param>
		/// <returns>置けるかどうか</returns>
		/// </summary>
		private bool CheckLine(int x, int y, int dx, int dy, ReversiColor color)
		{
			int i, j;
			ReversiColor inverse_color = InverseColor(color);
			for(i=x+dx, j=y+dy; this.board[i,j] == inverse_color; i+=dx, j+=dy);
			return !(i==x+dx && j==y+dy) && this.board[i,j]==color;
		}
コード例 #21
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		/// <summary>
		/// 駒の色と逆の色を返す
		/// </summary>
		/// <param name="color">駒の色</param>
		/// <returns>逆の色</returns>
		static public ReversiColor InverseColor(ReversiColor color)
		{
			if(color == ReversiColor.Black) return ReversiColor.White;
			if(color == ReversiColor.White) return ReversiColor.Black;
			return color;
		}
コード例 #22
0
ファイル: ReversiBoard.cs プロジェクト: ufcpp/UfcppSample
		//=========================================================
		// private methods

		/// <summary>
		/// 盤面の更新を1ラインずつ行う
		/// <param name="x">置く場所のx座標</param>
		/// <param name="y">置く場所のy座標</param>
		/// <param name="color">置く駒の色</param>
		/// </summary>
		private void UpdateLine(int x, int y, int dx, int dy, ReversiColor color)
		{
			int i, j;
			ReversiColor inverse_color = InverseColor(color);
			for(i=x+dx, j=y+dy; this.board[i,j] == inverse_color; i+=dx, j+=dy);
			if(!(i==x+dx && j==y+dy) && this.board[i,j]==color)
				for(i-=dx, j-=dy; !(i==x && j==y); i-=dx, j-=dy)
					this.board[i,j] = color;
		}