private void openButton_Click(object sender, EventArgs e) { var dialog = new OpenFileDialog() { Filter = "REVファイル|*.rev|すべてのファイル|*.*" }; if (dialog.ShowDialog() == DialogResult.OK) { try { record = MatchRecord.FromFile(dialog.FileName); var source = new BindingSource(); source.DataSource = record.Boards; bindingNavigator1.BindingSource = source; turnNum = Convert.ToInt32(bindingNavigatorPositionItem.Text); board = record.Boards[turnNum - 1]; RefreshTurnLabel(); RefreshPanel(); inPlayback = true; } catch { MessageBox.Show("ファイルが不正です。"); } } }
public void InitialState4x4() { var board = ReversiBoard.CreateInitialState(4, 4); Assert.AreSame(Player.WHITE, board[new Vector2D(1, 1)]); Assert.AreSame(Player.WHITE, board[new Vector2D(2, 2)]); Assert.AreSame(Player.BLACK, board[new Vector2D(1, 2)]); Assert.AreSame(Player.BLACK, board[new Vector2D(2, 1)]); Assert.IsNull(board[new Vector2D(0, 0)]); Assert.IsNull(board[new Vector2D(1, 0)]); Assert.IsNull(board[new Vector2D(2, 0)]); Assert.IsNull(board[new Vector2D(3, 0)]); Assert.IsNull(board[new Vector2D(0, 3)]); Assert.IsNull(board[new Vector2D(1, 3)]); Assert.IsNull(board[new Vector2D(2, 3)]); Assert.IsNull(board[new Vector2D(3, 3)]); Assert.IsNull(board[new Vector2D(0, 1)]); Assert.IsNull(board[new Vector2D(0, 2)]); Assert.IsNull(board[new Vector2D(3, 1)]); Assert.IsNull(board[new Vector2D(3, 2)]); }
/// <summary> /// Constructor /// Initializes varables /// </summary> public BoardViewModel(ReversiBoard board, OptionsViewModel options) { this.Rows = new List <BoardRowViewModel>(); this.Board = board; this.game = new ReversiGame(board.Width, board.Height); for (int f = 0; f < board.Height; f++) { var boardRow = new BoardRowViewModel(game); boardRow.SetWidth(board.Width); for (int s = 0; s < board.Width; s++) { boardRow.Squares[s].Owner = game.Board[new Vector2D(s, f)]; boardRow.Squares[s].PositionSquare = new Vector2D(s, f); } Rows.Add(boardRow); } this.CurrentPlayer = game.CurrentPlayer.ToString(); this.BlackStones = game.Board.CountStones(Player.BLACK); this.WhiteStones = game.Board.CountStones(Player.WHITE); this.PlayMusic = new PlayMusicCommand(new MediaPlayer()); this.Options = options; this.EndGame = new EndGameCommand(this, Options); this.BlackPlayer = Options.StartScreen.NameBlack; this.WhitePlayer = Options.StartScreen.NameWhite; SetWinner(); this.Command = new PutStoneNewBoardCommand(this); }
public CPU(ReversiBoard boarddata) { if (boarddata == null) { throw new NullReferenceException(); } BoardData = boarddata; }
public void InitialState2x2() { var board = ReversiBoard.CreateInitialState(2, 2); Assert.AreSame(Player.WHITE, board[new Vector2D(0, 0)]); Assert.AreSame(Player.WHITE, board[new Vector2D(1, 1)]); Assert.AreSame(Player.BLACK, board[new Vector2D(0, 1)]); Assert.AreSame(Player.BLACK, board[new Vector2D(1, 0)]); }
private void moveButton_Click(object sender, EventArgs e) { if (inPlayback) { turnNum = Convert.ToInt32(bindingNavigatorPositionItem.Text); board = record.Boards[turnNum - 1]; RefreshPanel(); RefreshTurnLabel(); } }
public OptionsViewModel() { var bordview = new BoardViewModel(ReversiBoard.CreateInitialState(6, 6), this); // hetzelfde spel wordt hier gebruikt, we gaan dezelfde bordview gebruiken om onze gegevens uit te halen this.OptionPanes = new List <object> { new OptionsCategory(new StartWindow(this)), new OptionsCategory(bordview),//Maakt bord aan }; this.SelectedOptionPane = OptionPanes.First(); }
public void NotifyElement() { this.board = game.Board; for (int i = 0; i < board.Height; i++) { for (int j = 0; j < board.Width; j++) { Rows[i].Squares[j].Owner = game.Board[new Vector2D(j, i)]; } } }
public void Execute(object parameter) // wat er gebeurt wanneer men op de knop zelf klikt { BoardViewModel bvm; bvm = new BoardViewModel(ReversiBoard.CreateInitialState(6, 6), viewModel);// waardes grote ingeven bvm.height = startWindow.height; bvm.width = startWindow.width; bvm = new BoardViewModel(ReversiBoard.CreateInitialState(bvm.width, bvm.height), viewModel); bvm.playerNameOne = startWindow.playerNameOne; bvm.playerNameTwo = startWindow.playerNameTwo; viewModel.SelectedOptionPane = new OptionsViewModel.OptionsCategory(bvm); System.Diagnostics.Debug.WriteLine(bvm.playerNameOne + " playerOne"); }
protected override void Start() { width = (int)Mathf.Sqrt(pieces.Length); base.Start(); boardSituation = new PieceType[pieces.Length]; for (int i = 0; i < pieces.Length; i++) { pieces[i].index = i; } policyValueNet = new ReversiPolicyValueNet(width); mctsPlayer = new MCTSPlayer(policyValueNet); board = new ReversiBoard(); }
public void Execute(object parameter) { BoardViewModel b; try { b = new BoardViewModel(ReversiBoard.CreateInitialState(StartScreen.Width, StartScreen.Height), Options); } catch (Exception) { b = new BoardViewModel(ReversiBoard.CreateInitialState(6, 6), Options); } Debug.WriteLine("Heigt= " + b.Board.Height); Debug.WriteLine("Width= " + b.Board.Width); Options.SelectedOptionPane = new OptionsViewModel.OptionsCategory(b); }
private async void Init() { turnNum = 0; passNum = 0; board = ReversiBoard.InitBoard(); record = MatchRecord.Empty(); //先手と後手で別の思考エンジンを使える senteEngine = new ThinkingEngine.RandomThinking(); goteEngine = new ThinkingEngine.CountingEngine(); RefreshTurnLabel(); RefreshPanel(); inGame = true; inPlayback = false; await Next(); }
private async Task Add(int row, int col) { if (!inGame) { return; } if (blocks[row, col].State != StoneType.None) { return; } turnNum++; if (turnNum % 2 == 1) { try { board = board.AddStone(row, col, StoneType.Sente); blocks[row, col].ToBlack(); //仮に打つ record.Boards.Add(board); } catch (ArgumentException) { turnNum--; } } else { try { board = board.AddStone(row, col, StoneType.Gote); blocks[row, col].ToWhite(); //仮に打つ record.Boards.Add(board); } catch (ArgumentException) { turnNum--; } } await Task.Delay(waitingTime); BeginInvoke(new Action(() => { RefreshPanel(); RefreshTurnLabel(); })); }
public void Execute(object parameter) { BoardViewModel bvm; try { bvm = new BoardViewModel(ReversiBoard.CreateInitialState(startWindow.Width, startWindow.Height), optionsView); bvm.playerOne = startWindow.playerOne; bvm.playerTwo = startWindow.playerTwo; } catch (Exception) { bvm = new BoardViewModel(ReversiBoard.CreateInitialState(6, 6), optionsView); bvm.playerOne = startWindow.playerOne; bvm.playerTwo = startWindow.playerTwo; } this.optionsView.SelectedOptionPane = new OptionsViewModel.OptionsCategory(bvm); }
/// <summary> /// 盤の情報をもとに思考し、次の手を返す /// </summary> /// <param name="board"></param> /// <param name="player"></param> /// <returns></returns> public Reversi.Core.ReversiMove Think(ReversiBoard board, StoneType player) { this.board = board; this.player = player; legalMoves = board.SearchLegalMoves(player); //合法手 if (legalMoves.Count == 0) { throw new InvalidOperationException("合法手がありません"); } else { var best = 0; var bestMove = default(ReversiMove); foreach (var item in board.SearchLegalMoves(player)) { var child = board.AddStone(item.Row, item.Col, player); switch (player) { case StoneType.None: break; case StoneType.Sente: if (best < child.NumOfBlack()) { best = child.NumOfBlack(); bestMove = item; } break; case StoneType.Gote: if (best < child.NumOfWhite()) { best = child.NumOfWhite(); bestMove = item; } break; default: break; } } return(bestMove); } }
public BoardViewModel(ReversiBoard board, OptionsViewModel options) { this.spel = new ReversiGame(board.Width, board.Height); this.Rows = new List <BoardRowViewModel>(); this.bord = board; this.black = bord.CountStones(Player.BLACK); this.white = bord.CountStones(Player.WHITE); this.currentPlayer = spel.CurrentPlayer; this.options = options; //timer var timeService = ServiceLocator.Current.GetInstance <ITimeService>(); _start = timeService.Now; _timer = ServiceLocator.Current.GetInstance <ITimerService>(); _timer.Tick += Timer_Tick; _timer.Start(new TimeSpan(0, 0, 0, 0, 100)); //this.Milliseconds = modelTimer.Milliseconds; for (var i = 0; i < board.Height; i++) { var rij = new BoardRowViewModel(spel); for (var j = 0; j < board.Width; j++) { rij.Squares[j].speler = spel.Board[new Vector2D(j, i)]; //breedte hoogte, j breedte i hoogte rij.Squares[j].Positie = new Vector2D(j, i); // nu is er aan elke square een juiste positie toegekend } Rows.Add(rij); } this.Command = new PutStoneCommand(this); // heeft een board nodig dus daarom de this we gaan deze direct meegeven this.commandend = new ToEndCommand(options, this); }
public BoardViewModel(Cell <GameInformation> info) { Game = Cell.Create <ReversiGame>(new ReversiGame(info.Value.Width, info.Value.Height)); Debug.WriteLine(info.ToString()); ReversiBoard board = Game.Value.Board; List <BoardRowViewModel> rows = new List <BoardRowViewModel>(); P1Name = info.Value.Player_One.Name; P2Name = info.Value.Player_Two.Name; for (int i = 0; i != board.Height; ++i) { List <BoardSquareViewModel> squares = new List <BoardSquareViewModel>(); for (int j = 0; j != board.Width; ++j) { squares.Add(new BoardSquareViewModel(i, j, Game, info.Value.Player_One.Color, info.Value.Player_Two.Color)); } rows.Add(new BoardRowViewModel(squares)); } this.Rows = rows; this.BlackCount = this.game.Derive(g => g.Board.CountStones(Player.BLACK)); this.WhiteCount = this.game.Derive(g => g.Board.CountStones(Player.WHITE)); this.CurrentPlayer = this.game.Derive(g => g.CurrentPlayer); }
public BoardViewModel(ReversiBoard reversiBoard, OptionsViewModel options) { try { this.game = new ReversiGame(reversiBoard.Width, reversiBoard.Height); System.Diagnostics.Debug.WriteLine(reversiBoard.Width); } catch { this.game = new ReversiGame(6, 6); } this.Rows = new List <BoardRowViewModel>(); this.Command = new PutStoneCommand(this); this.restartCommand = new RestartCommand(this); this.optionsView = options; this.endGameCommand = new EndGameCommand(optionsView, this); _timer = new DispatcherTimer(DispatcherPriority.Render); _timer.Interval = TimeSpan.FromSeconds(1); _timer.Tick += (sender, args) => { CurrentTime = DateTime.Now.ToLongTimeString(); }; _timer.Start(); for (int i = 0; i < game.Board.Height; i++) { var boardRow = new BoardRowViewModel(game); for (int j = 0; j < game.Board.Width; j++) { boardRow.Squares[j].Owner = game.Board[new Vector2D(j, i)]; boardRow.Squares[j].SquarePosition = new Vector2D(j, i); } Rows.Add(boardRow); } }
private async Task <Tuple <DiscordMember?, string> > PlayReversiRound(CommandContext ctx, DiscordMember player1, DiscordMember player2, bool keepMsgs) { ReversiBoard b = new ReversiBoard(); b.SetForNewGame(); bool currentPlayerIs1 = true; while (true) { currentPlayerIs1 = !currentPlayerIs1; ReversiBoard.Color player = currentPlayerIs1 ? ReversiBoard.Color.White : ReversiBoard.Color.Black; string renderedBoard = ""; renderedBoard += "```\n A B C D E F G H\n ┌─┬─┬─┬─┬─┬─┬─┬─┐"; for (int y = 0; y < 8; y++) { if (y != 0) { renderedBoard += "\n ├─┼─┼─┼─┼─┼─┼─┼─┤"; } renderedBoard += $"\n{y + 1}│"; for (int x = 0; x < 8; x++) { renderedBoard += b.GetSquareContents(y, x) switch { ReversiBoard.Color.Black => "O", ReversiBoard.Color.Empty => b.IsValidMove(player, y, x) ? "-" : " ", ReversiBoard.Color.White => "X", _ => throw new ArgumentOutOfRangeException() } } +"│"; } renderedBoard += "\n └─┴─┴─┴─┴─┴─┴─┴─┘\n```"; if (!b.HasAnyValidMove(player)) { if (!b.HasAnyValidMove(ReversiBoard.Invert(player))) { await ctx.RespondAsync(embed : new DiscordEmbedBuilder { Title = "Reversi", Description = b.WhiteCount == b.BlackCount ? "Tie!" : $"{(b.WhiteCount > b.BlackCount ? player1.DisplayName : player2.DisplayName)} won" }.AddField("Board", renderedBoard).Build()); DiscordMember?winner = b.WhiteCount == b.BlackCount ? null : b.WhiteCount > b.BlackCount ? player1 : player2; return(new Tuple <DiscordMember?, string>(winner, renderedBoard)); } continue; } DiscordMessage board = await ctx.RespondAsync(embed : new DiscordEmbedBuilder { Title = "Reversi", Description = $"Current turn: {(currentPlayerIs1 ? player1.DisplayName : player2.DisplayName)}" }.AddField("Board", renderedBoard).AddField("Tutorial", "Just respond with your column and row within one minute when it is your turn\n(eg: \"A5\")") .Build()); bool reading = true; DateTime trg = DateTime.Now + new TimeSpan(0, 1, 0); while (reading) { InteractivityResult <DiscordMessage> response = await ctx.Channel.GetNextMessageAsync(currentPlayerIs1?player1 : player2, trg - DateTime.Now); if (response.TimedOut) { await ctx.RespondAsync("Timed out."); return(null); } int[] text = response.Result.Content.ToLower().Select(s => (int)s).ToArray(); if (text.Length != 2 || text[0] < 97 || text[0] > 104 || text[1] < 49 || text[1] > 56) { await ctx.RespondAsync("Invalid."); } else { int x = text[0] - 97; int y = text[1] - 49; if (b.IsValidMove(player, y, x)) { if (!keepMsgs) { board.DeleteAsync(); } b.MakeMove(player, y, x); reading = false; } else { await ctx.RespondAsync("Invalid move."); } } } } }
private async Task RunAsync() { Console.Clear(); ConsoleView.Show(ReversiBoard.GetInitial()); await Task.CompletedTask; }
public ScreenA(Navigator navigator) : base(navigator) { this.BoardViewModel = new BoardViewModel(ReversiBoard.CreateInitialState(4, 4)); }
public void Setup() { board = new ReversiBoard(); }