public void Turn_matrix2() { //Arrange var board = new[, ] { { 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ' }, { ' ', 'O', ' ', ' ', 'O', ' ', ' ', 'X' }, { ' ', ' ', 'O', ' ', 'O', ' ', 'O', ' ' }, { ' ', ' ', ' ', 'O', 'O', 'O', ' ', ' ' }, { 'X', 'O', 'O', 'O', ' ', 'O', 'O', 'X' }, { ' ', ' ', ' ', 'O', 'O', 'O', ' ', ' ' }, { ' ', ' ', 'O', ' ', 'O', ' ', 'O', ' ' }, { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' }, }; var expected = new[, ] { { 'X', ' ', ' ', ' ', 'X', ' ', ' ', ' ' }, { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' }, { ' ', ' ', 'X', ' ', 'X', ' ', 'X', ' ' }, { ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ' }, { 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' }, { ' ', ' ', ' ', 'X', 'X', 'X', ' ', ' ' }, { ' ', ' ', 'X', ' ', 'X', ' ', 'X', ' ' }, { ' ', 'X', ' ', ' ', 'X', ' ', ' ', 'X' }, }; //Act var newBoard = Reversi.Move(board, 4, 4, 'X'); //Assert Assert.That(newBoard, Is.EqualTo(expected)); }
private void _InitP2P() { Send("INIT"); lock (MatchingList) { if (MatchingList.Count != 0) { var tuple = MatchingList[0]; MatchingList.RemoveAt(0); _Reversi = tuple.Item2; _Other = tuple.Item1; _Other._Other = this; if (new Random().NextDouble() >= 0.5) { _Player = ReversiPlayer.Dark; _Other._Player = ReversiPlayer.Light; } else { _Player = ReversiPlayer.Light; _Other._Player = ReversiPlayer.Dark; } _Other._Start(); _Start(); } else { _Reversi = new Reversi(); MatchingList.Add(new Tuple <ReversiBehavior, Reversi>(this, _Reversi)); } } }
private void _InitA2A() { Send("INIT"); Send("OBSV"); _Reversi = new Reversi(); _Player = 0; }
public ReversiAI(Reversi reversi, ReversiPlayer player, string modelUri) { _Reversi = reversi; _Player = player; _ModelUri = modelUri; _Device = DeviceDescriptor.GPUDevice(0); }
public void Placing_X_on_42_on_initial_board_should_return_a_board() { //Arrange var board = Reversi.GetInitialState(); //Act var newBoard = Reversi.Move(board, 4, 2, 'X'); //Assert }
public void Placing_disc_on_occupied_space_should_throw() { //Arrange var board = Reversi.GetInitialState(); //Act void newBoard() => Reversi.Move(board, 3, 3, 'X'); //Assert Assert.Throws <ReversiException>(newBoard); }
public void Music_From_off_to_onn_test() { Reversi Test = new Reversi(new System.Windows.Forms.Form(), new System.Windows.Forms.Form()); GameBox.Program.music_OnOff = false; Test.Bt_reversi_music(new System.Object(), EventArgs.Empty); Assert.AreEqual(Program.music_OnOff, true); Assert.AreNotEqual(Program.music_OnOff, false); }
public void Placing_X_on_54_on_initial_board_should_throw() { //Arrange var board = Reversi.GetInitialState(); //Act void newBoard() => Reversi.Move(board, 5, 4, 'X'); //Assert Assert.Throws <ReversiException>(newBoard); }
public void sum_empty_arr_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.sum(); Assert.AreEqual(Test.Lb_Score1.Text.ToString(), "2"); Assert.AreEqual(Test.Lb_Score2.Text.ToString(), "2"); Assert.AreNotEqual(Test.Lb_Score1.Text.ToString(), "3"); Assert.AreNotEqual(Test.Lb_Score2.Text.ToString(), "3"); Test.Close(); }
public void Placing_X_on_25_on_valid_board() { //Arrange var board = Reversi.GetInitialState(); board[4, 3] = 'X'; //Act void newBoard() => Reversi.Move(board, 2, 5, 'X'); //Assert Assert.Throws <ReversiException>(newBoard); }
public void Right_Up_slant_no_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 2] = 2; Test.arr[2, 0] = 2; Test.Right_Up_slant_check(2, 0, 2); Assert.AreEqual(Test.arr[1, 1], 0); Assert.AreNotEqual(Test.arr[1, 1], 2); Test.Close(); }
public void Left_Down_slant_no_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 2] = 2; Test.arr[2, 0] = 2; Test.left_Down_slant_check(0, 2, 2); Assert.AreEqual(Test.arr[1, 1], 0); Assert.AreNotEqual(Test.arr[1, 1], 2); Test.Close(); }
public void Left_row_check_no_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 0] = 2; Test.arr[0, 2] = 2; Test.Left_row_check(0, 2, 2); Assert.AreEqual(Test.arr[0, 1], 0); Assert.AreNotEqual(Test.arr[0, 1], 2); Test.Close(); }
public void Up_Down_check_no_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 0] = 2; Test.arr[2, 0] = 2; Test.Down_col_check(0, 0, 2); Assert.AreEqual(Test.arr[1, 0], 0); Assert.AreNotEqual(Test.arr[1, 0], 2); Test.Close(); }
public void sum_Player_two_Score_one_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 0] = 2; Test.sum(); Assert.AreEqual(Test.Lb_Score1.Text, "2"); Assert.AreEqual(Test.Lb_Score2.Text, "3"); Assert.AreNotEqual(Test.Lb_Score1.Text, "3"); Assert.AreNotEqual(Test.Lb_Score2.Text, "2"); Test.Close(); }
public void Left_Up_slant_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 0] = 2; Test.arr[1, 1] = 1; Test.arr[2, 2] = 2; Test.Left_Up_slant_check(2, 2, 2); Assert.AreEqual(Test.arr[1, 1], 2); Assert.AreNotEqual(Test.arr[1, 1], 1); Test.Close(); }
public void right_row_check_change_test() { Reversi Test = new Reversi(new Form(), new Form()); Test.arr[0, 0] = 2; Test.arr[0, 1] = 1; Test.arr[0, 2] = 2; Test.right_row_check(0, 0, 2); Assert.AreEqual(Test.arr[0, 1], 2); Assert.AreNotEqual(Test.arr[0, 1], 1); Test.Close(); }
public string UpdateGameState(Model.Game gameSession, int x, int y) { if (gameSession.State == Model.Game.GameState.Finished) { throw new ReversiException($"Game has finished, scores are: {gameSession.PlayerOne}={gameSession.PlayerOneScore} - {gameSession.PlayerTwo}={gameSession.PlayerTwoScore}"); } gameSession.State = Model.Game.GameState.Ongoing; var disc = gameSession.NextPlayer == gameSession.PlayerOne ? 'X' : 'O'; try { if (x == -1 && y == -1) { var moves = Reversi.GetMoves(gameSession.Board as char[, ], disc); if (moves.Length != 0) { throw new ReversiException("Only allowed to skip when no moves are available"); } // Two skips in a row = game finished var lastMove = gameSession.Moves.Last(); if (lastMove.X == -1 && lastMove.Y == -1) { gameSession.State = Model.Game.GameState.Finished; } } else { gameSession.Board = Reversi.Move(gameSession.Board as char[, ], x, y, disc); } gameSession.Turn++; gameSession.Moves.Add(new Model.Game.Move { Disc = disc, X = x, Y = y }); var otherDisc = disc == 'X' ? 'O' : 'X'; if (GetPossibleMoves(gameSession.Board as char[, ], disc).Length == 0 && GetPossibleMoves(gameSession.Board as char[, ], otherDisc).Length == 0) { gameSession.State = Model.Game.GameState.Finished; } return(null); } catch (ReversiException e) { return($"You did somthing you shouldn't have done...{Environment.NewLine}{e.Message}"); } }
public void Placing_X_on_24_on_initial_board_turns_discs() { //Arrange var board = Reversi.GetInitialState(); var expected = Reversi.GetInitialState(); expected[4, 2] = 'X'; expected[4, 3] = 'X'; //Act var newBoard = Reversi.Move(board, 2, 4, 'X'); //Assert Assert.That(newBoard, Is.EqualTo(expected)); }
public void Turn_picture_box_no_change_White_test() { Reversi Test = new Reversi(new Form(), new Form()); PictureBox Help = new PictureBox(); System.Drawing.Bitmap BlackImage = (System.Drawing.Bitmap)GameBox.Properties.Resources.Black_piece; System.Drawing.Bitmap WhiteImage = (System.Drawing.Bitmap)GameBox.Properties.Resources.white_piece; Help.BackgroundImage = GameBox.Properties.Resources.white_piece; Test.Turn_picture_box_White(Help); System.Drawing.Bitmap HelpImage = (System.Drawing.Bitmap)Help.BackgroundImage; Assert.AreEqual(HelpImage.Flags.ToString(), WhiteImage.Flags.ToString()); Assert.AreNotEqual(HelpImage.Flags.ToString(), BlackImage.Flags.ToString()); Test.Close(); }
private void _InitP2A() { Send("INIT"); _Reversi = new Reversi(); if (new Random().NextDouble() >= 0.5) { _Player = ReversiPlayer.Dark; _AI0 = new ReversiAI(_Reversi, ReversiPlayer.Light, Path); // TODO } else { _Player = ReversiPlayer.Light; _AI0 = new ReversiAI(_Reversi, ReversiPlayer.Dark, Path); } _Start(); }
/// <summary> /// コンストラクタ /// </summary> public Board_ViewModel(Reversi.Engine.Board boardModel) { _boardModel = boardModel; SquareList = new ObservableCollection<Square_ViewModel>(); for (int x = 1; x <= Reversi.Engine.Reversi.BOARD_SIZE ; x++) { for (int y = 1; y <= Reversi.Engine.Reversi.BOARD_SIZE ; y++) { int color = _boardModel.getColor(x, y); var item = new Square_ViewModel(); item.x = x; item.y = y; SquareList.Add(item); } } Reflesh(); }
public string AssignGameAgainstRandomBot(string playerKey) { var gameKey = Guid.NewGuid().ToString(); var g = new Model.Game { Board = Reversi.GetInitialState(), PlayerOne = playerKey }; var added = _database.TryAdd(gameKey, g); if (!added) { throw new ApplicationException("Game already added"); } var botName = $"randy_{Guid.NewGuid().ToString().Replace("-", "")}"; g.PlayerTwo = botName; return(gameKey); }
// Start is called before the first frame update void Start() { reversi = new Reversi(); // ゲーム開始時にreversi.Boardの状態を確認し、ボードの描画状態を更新する。 ConfirmBord(); UpdatePutMark(); UpdateScore(); Debug.Log(reversi.Turn); //// typeで指定した型の全てのオブジェクトを配列で取得し,その要素数分繰り返す. //foreach (GameObject obj in UnityEngine.Object.FindObjectsOfType(typeof(GameObject))) //{ // // シーン上に存在するオブジェクトならば処理. // if (obj.activeInHierarchy) // { // // GameObjectの名前を表示. // Debug.Log(obj.name); // } //} }
public string AssignGame(string playerKey) { var game = _database.FirstOrDefault(x => string.IsNullOrEmpty(x.Value.PlayerTwo)); if (game.Key is default(string)) { var gameKey = Guid.NewGuid().ToString(); var g = new Model.Game { Board = Reversi.GetInitialState(), PlayerOne = playerKey }; var added = _database.TryAdd(gameKey, g); if (!added) { throw new ApplicationException("Game already added"); } return(gameKey); } game.Value.PlayerTwo = playerKey; return(game.Key); }
internal static char ToChar(Reversi source) => ToChar((uint)source);
public static Char ToChar(this Reversi source) => ReversiBoard.ToChar(source);
/// <returns>row</returns> public uint Set(int row, int column, Reversi source) => Set(row, column, (uint)source);
static void Main(string[] args) { char i, j; Console.WriteLine(); Reversi reversi = new Reversi(); while (((int)reversi.GetState() & 1) != 0) { Console.Write(reversi); while (Char.IsWhiteSpace(i = (char)Console.Read())) { ; } while (Char.IsWhiteSpace(j = (char)Console.Read())) { ; } Console.Clear(); if (Char.IsLower(i)) { i -= ' '; } if (Char.IsLower(j)) { j -= ' '; } if (i == 'Z' && j == 'Z') { if (!reversi.Undo()) { Console.WriteLine("Cannot undo."); } else { Console.WriteLine("Undid."); } } else if (i == 'Y' && j == 'Y') { if (!reversi.Redo()) { Console.WriteLine("Cannot redo."); } else { Console.WriteLine("Redid."); } } else if (i == 'S' && j == 'S') { if (!reversi.SkipTurn()) { Console.WriteLine("Cannot skip the turn."); } else { Console.WriteLine("Skipped."); } } else if (!Char.IsDigit(i) || !Char.IsLetter(j)) { Console.WriteLine("Invalid command."); } else { if (!reversi.PlacePiece(i - '1', j - 'A')) { Console.WriteLine("Cannot place."); } else { if (reversi.GetState() == ReversiState.NoAvailableSpaces) { Console.WriteLine("No available spaces."); } else { Console.WriteLine(); } } } } }
public override void OnStart(Dictionary <string, object> args) { game = new Reversi(); if (args.ContainsKey("mode") && args["mode"] is string mode) { switch (mode) { case "Multiplayer": Mode = GameMode.MultiPlayer; break; case "SimpleAI": ai = new SimpleAi(game); Mode = GameMode.VsCpu; break; case "DynamicAI": Mode = GameMode.VsCpu; break; case "RandomAI": ai = new RandomAi(game); Mode = GameMode.VsCpu; break; default: break; } } boardView = new Container(); boardView.Scale *= 2; Root.Add(boardView); var title = new TextElement("リバーシするヤーツ", DFFont.GetDefault(32), Color.White) { Location = (32, 32) }; Root.Add(title); turn = new TextElement("のターン", DFFont.GetDefault(16), Color.White); Root.Add(turn); score = new TextElement("黒 / 白", DFFont.GetDefault(16), Color.White); Root.Add(score); tileStoneBlack = Tile.LoadFrom("resources/textures/stone-black.png"); tileStoneWhite = Tile.LoadFrom("resources/textures/stone-white.png"); tilePrompt = Tile.LoadFrom("resources/textures/prompt.png"); var backdrop = new Sprite("resources/textures/board.png"); boardView.Add(backdrop); stones = new Tilemap((16, 16)); boardView.Add(stones); aud.Play(bgmMain, 0); boardView.Location = (DF.Window.Size.X / 2 - 128, 96); Render(); }
public SimpleAi(Reversi game) { this.game = game; }