/// <summary> /// Minimum GameBoard ist 9x9 Tiles. /// </summary> /// <param name="width">9 for everything < 8</param> /// <param name="height">9 for everything < 8</param> public GameBoard(BoardSize boardSize) { switch (boardSize) { case BoardSize.Beginner: Width = 9; Height = 9; NumberOfMines = 10; break; case BoardSize.Medium: Width = 16; Height = 19; NumberOfMines = 40; break; case BoardSize.Difficult: Width = 30; Height = 16; NumberOfMines = 99; break; } Tiles = CreateTiles(Width, Height); SetRandomMines(); CalculateAdjacentMines(); }
private void OnCreateNewBoard(object parameter) { if (parameter == null) { this.Minesweeper = MinesweeperFactory.Create(this.Minesweeper); return; } if (parameter is BoardSize) { this.Minesweeper = MinesweeperFactory.Create((BoardSize)parameter); } else if (parameter is string) { var text = (string)parameter; if (text.StartsWith("*")) { var boardSize = new BoardSize(this.Minesweeper.Tiles.Width, this.Minesweeper.Tiles.Height, this.Minesweeper.MineCount); this.Minesweeper = MinesweeperFactory.Create(boardSize); } else { var boardSize = BoardSize.Parse(parameter.ToString()); this.Minesweeper = MinesweeperFactory.Create(boardSize); } } else { throw new ArgumentException("parameter must either be of type String or BoardSize, or be set to null."); } }
/// <summary> /// Creates a new <see cref="FourInARowGame"/>. /// </summary> /// <param name="playerOne">Name of player one.</param> /// <param name="playerTwo">Name of player two.</param> /// <param name="boardSize">The <see cref="BoardSize"/>.</param> public FourInARowGame(string playerOneName, string playerTwoName, BoardSize boardSize) { PlayerOne = new Player(playerOneName, BoardSlotValue.P1); PlayerTwo = new Player(playerTwoName, BoardSlotValue.P2); _boardGrid = new BoardGrid(boardSize); _playerSwitcher = new PlayerSwitcher(new [] { PlayerOne, PlayerTwo }); }
// POST api/games public HttpResponseMessage Post(BoardSize size) { if (ModelState.IsValid) { var game = new Game { Id = games.Count + 1, Winner = -1, Board = new int[size.Width * size.Height], HSize = size.Width, VSize = size.Height, Players = new List <int> { 1 }, CurrentPlayer = 1 }; games.Add(game); var response = Request.CreateResponse(HttpStatusCode.Created, new { Player = 1, GameId = game.Id }); var uri = Url.Link("DefaultAPI", new { id = game.Id }); response.Headers.Location = new Uri(uri); return(response); } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "bad input")); }
public Board(BoardSize n) { digits = n == BoardSize.s9 ? 1 : 2; unitSize = (int)n; boardSize = unitSize * unitSize; data = new int[boardSize * boardSize]; }
internal static List <Move> GetValidMoves4x4(bool fullBoard, BoardSize boardSize) { var validMoves = new List <Move> { Move.FromPositionAndDirection(2, 1, Direction.Down, boardSize), // equivalent to (1, 1, Up) Move.FromPositionAndDirection(1, 1, Direction.Down, boardSize), Move.FromPositionAndDirection(1, 1, Direction.Left, boardSize), Move.FromPositionAndDirection(1, 1, Direction.Right, boardSize), Move.FromPositionAndDirection(0, 1, Direction.Left, boardSize), }; if (fullBoard) { // This would move out of range on the small board // Equivalent to (3, 1, Down) validMoves.Add(Move.FromPositionAndDirection(2, 1, Direction.Up, boardSize)); // These moves require matching with a cell that's off the small board, so they're invalid // (even though the move itself doesn't go out of range). validMoves.Add(Move.FromPositionAndDirection(2, 1, Direction.Left, boardSize)); // Equivalent to (2, 0, Right) validMoves.Add(Move.FromPositionAndDirection(2, 1, Direction.Right, boardSize)); } return(validMoves); }
// ------------------------------------------------------------------------------------- // Public Funtion public void InitGame(bool _continue = false) { // Load Data var playersInfo = DataManager.PlayersInfo; // Init Variable _GameStageList = new List <GameStage>(); _BoardSize = DataManager.BoardSize; _TurnCount = 0; _IsAddScore = false; if (!_continue) { InitPlayerInfo(playersInfo); } // Start Game _TurnCount++; var boardData = new int[(int)_BoardSize, (int)_BoardSize]; var stage = new GameStage(_BoardSize, boardData, _PlayersName, GetPlayerName()); _GameStageList.Add(stage); _Status = true; _Disposable?.Dispose(); _Disposable = OnTurnProcessAsObservable().Subscribe().AddTo(this); OnGameCompleted().Subscribe().AddTo(this); }
// ------------------------------------------------------------------------------------- // Unity Funtion public override void Awake() { base.Awake(); // Set Default _PlayersInfo = m_PlayerInfoDefault; _BoardSize = m_MatchSizeDefault; }
public void BoardBuilder_creates_board_with_correct_number_of_mines(BoardSize boardSize, int numMines) { var builder = new BoardBuilder(boardSize); var board = builder.Build(); CountMines(board.Tiles).Should().Be(numMines); }
public Board(BoardSize size) { _position = Console.CursorTop; // cursor เริ่มต้นของตาราง Size = size; CreateTable(); }
public void CreateGameBoard_ValidParameter_BoardCreatedSuccesfully(BoardSize boardSize, int expectedArrSize) { var actualGameBoard = Game.CreateGameBoard(boardSize); Assert.NotNull(actualGameBoard); Assert.Equal(expectedArrSize, actualGameBoard.Length); }
public Game(BoardSize boardSize) { var builder = new BoardBuilder(boardSize); Board = builder.Build(); Status = GameStatus.Started; }
public GameSettings(BoardSize i_BoardSize, GameMode i_Mode, string i_Player1Name, string i_Player2Name) { this.m_BoardSize = i_BoardSize; this.m_Mode = i_Mode; this.m_Player1Name = i_Player1Name; this.m_Player2Name = i_Player2Name; }
public Boggle(ScoringMode score_mode = ScoringMode.SCRABBLE, BoardSize board_size = BoardSize.BIGBOGGLE, BoundaryMode bound_mode = BoundaryMode.STANDARD, int time_limit = 180000, int min_length = 3) { status = GameStatus.PRE_GAME; score = 0; mode = score_mode; size = board_size; minLength = min_length; gameLength = time_limit; bound = bound_mode; dice = new string[(int)size, 6]; //Create the array to hold dice values position = new int[(int)size]; //Array of positions on board board = new string[(int)size]; //Array containing the layout of the board gameTimer.Enabled = false; gameTimer.Interval = (double)gameLength; gameTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); current_word_list = "../../enable2k.txt"; if (size == BoardSize.STANDARD) { current_dice_set = "../../BoggleDice.txt"; } else { current_dice_set = "../../BigBoggleDice.txt"; } LoadDice(); LoadWordList(); ShuffleBoard(); }
public void Constructor_generates_new_board_based_on_given_BoardSize( BoardSize expectedSize) { var sut = new BoardGrid(expectedSize.Width, expectedSize.Height); Assert.Equal(sut.Columns * sut.Rows, sut.State.Count); }
public void BoardBuilder_creates_correct_size_board(BoardSize boardSize, int numRows, int numCols) { var builder = new BoardBuilder(boardSize); var board = builder.Build(); board.Tiles.GetLength(0).Should().Be(numRows); board.Tiles.GetLength(1).Should().Be(numCols); }
public void Start(BoardSize size) { var tileCount = GetTileCountFromBoardSize(size); var bombCount = tileCount / 6; var gen = new MineSweeperBoardGenerator(tileCount, bombCount); this.BoardTiles = gen.GetBoard(); }
public void Constructor_generates_a_board_based_on_given_BoardSlotValue_array( BoardSlotValue[,] boardSlotValues, BoardSize expectedSize) { var sut = new BoardGrid(boardSlotValues); Assert.Equal(expectedSize, sut.ToBoardSize()); Assert.Equal(expectedSize.Height, sut.Rows); Assert.Equal(expectedSize.Width, sut.Columns); }
private GameLogic() { Players = new List <Player>(); Fields = new List <Field>(); BoardSize = new BoardSize(); CurrentRound = new Round(); CurrentRound.GameState = GameState.Move; }
/// <summary> /// The max distance traveled by a single "line of sight" bouncing along mirrors /// </summary> /// <param name="boardSize"></param> /// <returns></returns> public int MaxPaths(BoardSize boardSize) { int maxPaths = 0; if (boardSizeToMaxPath.ContainsKey(boardSize)) { maxPaths = boardSizeToMaxPath[boardSize]; } return(maxPaths); }
public void TestInvalidMove(int row, int col, Direction dir) { var board10x10 = new BoardSize { Rows = 10, Columns = 10 }; Assert.Throws <IndexOutOfRangeException>(() => { Move.FromPositionAndDirection(row, col, dir, board10x10); }); }
private IEnumerator MoveTests(BoardSize size, TileValue[] positions, TileValue[] expected, bool valid, TileMover.Direction dir) { TileMover mover = SetupBasicField(size); yield return(null); yield return(null); Dictionary <BoardPos, Tile> board = mover.getBoardRepresentation(); foreach (TileValue position in positions) { board[position.Grid].setTile(position.Val, Color.blue, Color.black); } yield return(null); yield return(null); LogAssert.Expect(LogType.Log, (valid ? "valid " : "invalid ") + dir.ToString().ToLower() + " move"); switch (dir) { case TileMover.Direction.Up: mover.Up(); break; case TileMover.Direction.Down: mover.Down(); break; case TileMover.Direction.Left: mover.Left(); break; case TileMover.Direction.Right: mover.Right(); break; default: Assert.Fail("Direction was unknown"); break; } yield return(null); board = mover.getBoardRepresentation(); foreach (TileValue tileValue in expected) { Assert.IsTrue(board.ContainsKey(tileValue.Grid), "Expected value could not be found"); Assert.AreEqual(tileValue.Val, board[tileValue.Grid].Value); } }
/// <summary> /// Retrieve unit price for a given state and board size. /// </summary> public decimal GetUnitPrice(string state, BoardSize size) { decimal price = 0m; UnitPrice result = GetAllPrices().Where(p => p.BSize == size && p.State == state).FirstOrDefault(); if (result != null) { price = result.Price; } return(price); }
public Board(BoardSize n) { switch (n) { case BoardSize.s9: unitSize = 3; boardSize = 9; dataDigits = 1; flagDigits = 3; flagDefault = 0x000001ff; break; case BoardSize.s16: unitSize = 4; boardSize = 16; dataDigits = 2; flagDigits = 4; flagDefault = 0x0000ffff; break; case BoardSize.s25: unitSize = 5; boardSize = 25; dataDigits = 2; flagDigits = 7; flagDefault = 0x01ffffff; break; default: throw (new ArgumentException()); } for (int i = 0; i < boardSize * 3; i++) { GroupList.Add(new List <Cell>()); } data = new Cell[boardSize * boardSize]; for (int row = 0; row < boardSize; row++) { for (int col = 0; col < boardSize; col++) { int i = col + row * boardSize; int group = col / unitSize + (row / unitSize) * unitSize; data[i] = new Cell(col, row, group); data[i].Flag = flagDefault; GroupList[col].Add(data[i]); GroupList[row + boardSize].Add(data[i]); GroupList[group + boardSize * 2].Add(data[i]); } } }
// バイト列に変換して送信データに書き込むメソッド private static short SerializeBoardSize(StreamBuffer outStream, object customObject) { BoardSize boardSize = (BoardSize)customObject; int index = 0; lock (bufferBoardSize) { Protocol.Serialize(boardSize.Value.x, bufferBoardSize, ref index); Protocol.Serialize(boardSize.Value.y, bufferBoardSize, ref index); outStream.Write(bufferBoardSize, 0, index); } return((short)index); // 書き込んだバイト数を返す }
protected TileMover SetupBasicField(BoardSize size) { GameObject gameSize = new GameObject("GameSize"); { GameOption settings = gameSize.AddComponent <GameOption>(); settings.Option = new SizeSelector.GameSize() { X = size.X, Y = size.Y, Name = "test" }; } GameObject root = new GameObject("root"); { root.AddComponent <Canvas>(); } GameObject tile = new GameObject("Tile", new[] { typeof(Tile), typeof(Image) }); { GameObject text = new GameObject("text", new[] { typeof(Text) }); text.transform.SetParent(tile.transform); Tile t = tile.GetComponent <Tile>(); Image img = tile.GetComponent <Image>(); Text txt = text.GetComponent <Text>(); t.setSerials(img, txt); } GameObject builder = new GameObject("board", new[] { typeof(RectTransform) }); builder.transform.SetParent(root.transform); BoardBuilder bld = builder.AddComponent <BoardBuilder>(); bld.setPrefab(tile); TileMover mover = builder.AddComponent <TileMover>(); mover.AddStyle(new TileStyle { Color = Color.yellow, score = 2, SecondaryTextColour = false }); mover.AddStyle(new TileStyle { Color = Color.red, score = 4, SecondaryTextColour = false }); mover.Score = 1; mover.AddUnknownStyle(new TileStyle { Color = Color.black, score = 4, SecondaryTextColour = true }); return(mover); }
protected List <int> GetVerticalStep(BoardSize size) { var step = new List <int>(); for (int row = 0; row < (int)size; row++) { for (int col = 0; col < (int)size; col++) { step.Add(row + (col * (int)size)); } } return(step); }
private void SetupBoardSize(LevelData level) { boardSize = new BoardSize(level.numCols, level.numRows); // boardStartOffset is used to get the bottom-left position // We want board centered horizontally and vertically float offsetX = (boardSquareSize.width * boardSize.numCols) * -0.5f; float offsetY = ((boardSquareSize.height * boardSize.numRows) * -0.5f); boardStartOffset = new Vector2(offsetX, offsetY); // Adjust touch collider to fit the board shape touchInput.ResizeColliderForBoard(boardSize, boardSquareSize); }
/// <summary> /// Method to check if the little turtle has moved outside the bounds of the game board /// and updates the turtle's status. /// </summary> /// <param name="littleTurtle">Our brave little turtle <see cref="LittleTurtle"/>.</param> /// <param name="boardSize">The board size.</param> /// <returns></returns> private static bool CheckForOutOfBounds(LittleTurtle littleTurtle, BoardSize boardSize) { if (littleTurtle.CurrentPosition.X < 0 || littleTurtle.CurrentPosition.Y < 0 || littleTurtle.CurrentPosition.X >= boardSize.Length || littleTurtle.CurrentPosition.Y >= boardSize.Width) { littleTurtle.Status = TurtleStatus.Lost; return(true); } else { return(false); } }
public void TestMoveEquivalence() { var board10x10 = new BoardSize { Rows = 10, Columns = 10 }; var moveUp = Move.FromPositionAndDirection(1, 1, Direction.Up, board10x10); var moveDown = Move.FromPositionAndDirection(2, 1, Direction.Down, board10x10); Assert.AreEqual(moveUp.MoveIndex, moveDown.MoveIndex); var moveRight = Move.FromPositionAndDirection(1, 1, Direction.Right, board10x10); var moveLeft = Move.FromPositionAndDirection(1, 2, Direction.Left, board10x10); Assert.AreEqual(moveRight.MoveIndex, moveLeft.MoveIndex); }
public int Start(string selected, BoardSize size, AiLevel level, bool first) { var score = new GameScore(); do { var symbol = GetSymbolForPlayer(selected); var player = first ? symbol.Item1 : symbol.Item2; var game = new OxGame(size); var board = new Board(size); var human = new Human(symbol.Item1); var ai = new AI(symbol.Item2, level); // game loop while (game.GameState == State.Playing) { if (player == human.Symbol) { // ตาผู้เล่น game.CheckError(PlayerTurn(game, board, human)); player = ChangeTurn(player); } else { // ตา ai game.CheckError(PlayerTurn(game, board, ai)); player = ChangeTurn(player); } } if (game.GameState == State.Win || game.GameState == State.Draw) { // นับสถิติการแข่งขัน AddSore(game, score, human, ai); } else if (game.GameState == State.Error) { // แสดงข้อผิดพลาด DisplayError(); } } while (PlayAgain()); score.Summary(); return(0); }
public static string[] CreateGameBoard(BoardSize boardSize) { switch (boardSize) { case BoardSize.ThreeXThree: return(new string[9]); case BoardSize.FourXFour: return(new string[16]); case BoardSize.FiveXFive: return(new string[25]); default: throw new ArgumentException("Bad enum type"); } }
private void OnCreateNewBoard(object parameter) { if (parameter == null) { this.Minesweeper = MinesweeperFactory.Create(this.Minesweeper); return; } if (parameter is BoardSize) { this.Minesweeper = MinesweeperFactory.Create((BoardSize)parameter); } else if (parameter is string) { var text = (string)parameter; if (text.StartsWith("*")) { var boardSize = new BoardSize(this.Minesweeper.Tiles.Width, this.Minesweeper.Tiles.Height, this.Minesweeper.MineCount); this.Minesweeper = MinesweeperFactory.Create(boardSize); } else { var boardSize = BoardSize.Parse(parameter.ToString()); this.Minesweeper = MinesweeperFactory.Create(boardSize); } } else { throw new ArgumentException("parameter must either be of type String or BoardSize, or be set to null."); } }
private void radSizeStandard_CheckedChanged(object sender, EventArgs e) { if (radSizeStandard.Checked) { boardSize = BoardSize.STANDARD; } }
private void radSizeBig_CheckedChanged(object sender, EventArgs e) { if (radSizeBig.Checked) { boardSize = BoardSize.BIGBOGGLE; } }
public BoggleGUI(Options c, Color valid_move, Color selected_move, ScoringMode score_mode = ScoringMode.SCRABBLE, BoardSize board_size = BoardSize.BIGBOGGLE, BoundaryMode bound_mode = BoundaryMode.STANDARD, int t_limit = 180000, int min_length = 3) { InitializeComponent(); caller = (Options)c; colorValid = valid_move; colorSelected = selected_move; scoreMode = score_mode; boardSize = board_size; boundMode = bound_mode; timeLimit = t_limit; wordMin = min_length; string dice = caller.customDice; string word = caller.customWords; //Create psuedo control array btnArray = new Button[(int)boardSize]; btnArray[0] = button1; btnArray[1] = button2; btnArray[2] = button3; btnArray[3] = button4; btnArray[4] = button5; btnArray[5] = button6; btnArray[6] = button7; btnArray[7] = button8; btnArray[8] = button9; btnArray[9] = button10; btnArray[10] = button11; btnArray[11] = button12; btnArray[12] = button13; btnArray[13] = button14; btnArray[14] = button15; btnArray[15] = button16; if (boardSize == BoardSize.BIGBOGGLE) // If Big Boggle need all the buttons { btnArray[16] = button17; btnArray[17] = button18; btnArray[18] = button19; btnArray[19] = button20; btnArray[20] = button21; btnArray[21] = button22; btnArray[22] = button23; btnArray[23] = button24; btnArray[24] = button25; } else // Else if Standard hide the extra buttons { button17.Visible = false; button18.Visible = false; button19.Visible = false; button20.Visible = false; button21.Visible = false; button22.Visible = false; button23.Visible = false; button24.Visible = false; button25.Visible = false; int btnNumber = 0; for (int row = 0; row < 4; row++) //Rearrange the buttons into a 4x4 grid { for (int col = 0; col < 4; col++) { Point myPoint = new Point(41 * (col % 4), (41 * row)); btnArray[btnNumber].Location = myPoint; btnNumber++; } } } }
public static IMinesweeper Create(BoardSize board) { return Minesweeper.Create(board.Width, board.Height, board.MineCount); }
// Methods public void Start(BoardSize boardSize) { Int32 size = (Int32) boardSize; board = new Piece[size, size]; if(started) { Stop(); } started = true; }