コード例 #1
0
 public GameManager(IGameRules rules)
 {
     Board = new ObservableCollection<int>();
     Rules = rules;
     BindingOperations.EnableCollectionSynchronization(board, _lock);
     this.GameFinished = true;
 }
コード例 #2
0
ファイル: MinMax.cs プロジェクト: francisquinha/IART
 public MinMax(VERSION version, IGameRules <GAME_BOARD, GAME_MOVE_DESCRIPTION> rules, int max_depth = 0)
 {
     this.version   = version;
     this.rules     = rules;
     this.max_depth = max_depth;
     useSmartDepth  = max_depth == USE_SMART_DEPTH;
 }
コード例 #3
0
 public ConstructForm(IDataProvider dataProvider, IGameRules gameRules)
 {
     questionController = new QuestionController(dataProvider, gameRules);
     questionController.RefreshPackNameList();
     InitializeComponent();
     PackList.Items.AddRange(questionController.packNameList.ToArray());
 }
コード例 #4
0
        public BoundaryLessGrid CreateNextGeneration(IGameRules gameRules)
        {
            var nextGen = Clone(_cells);


            for (int x = 0; x < _cells.GetLength(0); x++)
            {
                for (int y = 0; y < _cells.GetLength(1); y++)
                {
                    var currentCellReadonly = _cells[x, y].GetReadOnlyVersion();
                    var nextState           = gameRules.GetNextState(currentCellReadonly, GetNeighbours(x, y));
                    if (nextState == CellState.Alive && _cells[x, y].IsDead())
                    {
                        nextGen[x, y].Revive();
                    }
                    else if (nextState == CellState.Dead)
                    {
                        nextGen[x, y].Kill();
                    }
                }
            }


            return(new BoundaryLessGrid(nextGen));
        }
コード例 #5
0
        public void SetUp()
        {
            var rulesDictionary = new Dictionary <GameAction, List <GameAction> >()
            {
                {
                    GameAction.Rock,
                    new List <GameAction>()
                    {
                        GameAction.Scissors
                    }
                },
                {
                    GameAction.Paper,
                    new List <GameAction>()
                    {
                        GameAction.Rock
                    }
                },
                {
                    GameAction.Scissors,
                    new List <GameAction>()
                    {
                        GameAction.Paper
                    }
                }
            };

            GameRules        = new GameRules(rulesDictionary);
            PlayerMocks      = new List <Mock <IPlayer> >();
            Players          = new List <IPlayer>();
            Moves            = new List <IMove>();
            UiControllerMock = new Mock <IUserInteraction>();
        }
コード例 #6
0
 public QuestionController(IDataProvider dataProvider, IGameRules gameRules)
 {
     GameRules        = gameRules;
     DataProvider     = dataProvider;
     timer.Tick      += new EventHandler(Timer_Tick);
     TimeLeftToAnswer = GameRules.TimeToAnswer;
     questionPack     = new QuestionPack(gameRules);
 }
コード例 #7
0
        public Game(IGameRules gameRules)
        {
            this.gameRules = gameRules;

            Arena     = new Arena(this.gameRules.ARENA_WIDTH, this.gameRules.ARENA_HEIGHT);
            Teams     = new List <Team>();
            PodRacers = new List <PodRacer>();
        }
コード例 #8
0
 public SantaseGame(IPlayer firstPlayer, IPlayer secondPlayer, IGameRules gameRules, ILogger logger)
 {
     this.RestartGame();
     this.firstPlayer  = firstPlayer;
     this.secondPlayer = secondPlayer;
     this.gameRules    = gameRules;
     this.logger       = logger;
 }
コード例 #9
0
 public SantaseGame(IPlayer firstPlayer, IPlayer secondPlayer, IGameRules gameRules, ILogger logger)
 {
     this.RestartGame();
     this.firstPlayer = firstPlayer;
     this.secondPlayer = secondPlayer;
     this.gameRules = gameRules;
     this.logger = logger;
 }
コード例 #10
0
        public Move MakeMove(IGameRules gameRules)
        {
            var validOptions    = gameRules.ValidOptions.ToList();
            var numberOfOptions = validOptions.Count;

            string moveToMake = validOptions[_rand.Next(0, numberOfOptions)];

            return(new Move(this, moveToMake));
        }
コード例 #11
0
 public SpaceShip(IGameRules gameRules)
 {
     size           = gameRules.Width / SIZE_RATIO;
     leftBoundary   = topBoundary = 0 - size / 4;
     rightBoundary  = gameRules.Width - size * (3.0 / 4);
     bottomBoundary = gameRules.Height - size * (3.0 / 4);
     x = gameRules.Width / 2 - size / 2;
     y = gameRules.Height - size - gameRules.Height / 30;
 }
コード例 #12
0
ファイル: GameState.cs プロジェクト: zzymyn/TgmTasHelper
 public GameState(TetrominoType firstBlock, IGameRules gameRules, IRng rng)
 {
     NextTetromino = firstBlock;
     GameRules     = gameRules;
     Rng           = rng;
     Board         = new MutableBoard(gameRules);
     Time          = 0;
     Level         = 0;
 }
コード例 #13
0
 public AsteroidsGame(IGameRules gameRules, int fps)
 {
     this.gameRules     = gameRules;
     viewUpdateInterval = 0 == fps ? 0 : 1000 / fps;
     timer          = new Timer(gameRules.SpeedMs);
     timer.Elapsed += gameLoop;
     stopWatch      = new Stopwatch();
     GameState      = EGameState.GameOver;
 }
コード例 #14
0
        public PlayerFactory(IPlayerEntity playerEntity, IGameRules gameRules, IFrameEntity frameEntity, IFrameMapper frameMapper)
        {
            GameRules = gameRules;

            FrameEntity = frameEntity;

            PlayerEntity = playerEntity;

            FrameMapper = frameMapper;
        }
コード例 #15
0
        public Player(IMove move, IPosition startPosition,
                      int lives, IBoardRules boardRules, IGameRules playerReaction)
        {
            this.move = move;

            numberOfLives       = lives;
            this.boardRules     = boardRules;
            this.playerReaction = playerReaction;
            currentPosition     = startPosition;
        }
コード例 #16
0
        public GameStateMachine CreateNewGame(IGameRules gameRules)
        {
            var gameId = Guid.NewGuid();
            var game   = TryCreateGame(gameId, gameRules);

            if (game == null)
            {
                throw new InvalidOperationException($"Failed to create new game: {gameId}");
            }
            return(game);
        }
コード例 #17
0
        public static IGame CreateGame
        (
            IGameRules rules,
            IPlayer player1,
            IPlayer player2,
            byte gameSize
        )
        {
            var history = new History();

            return(new Implementations.Game(rules, player1, player2, history, gameSize));
        }
コード例 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="title"></param>
 /// <param name="author"></param>
 /// <param name="players"></param>
 /// <param name="rules"></param>
 /// <param name="interactionController"></param>
 /// <param name="match"></param>
 /// <param name="score"></param>
 /// <param name="matchResult"></param>
 public Application(string title, string author, List <IPlayer> players, IGameRules rules,
                    IUserInteraction interactionController, Contest match, IScore score, IContestResult matchResult)
 {
     Title   = title;
     Author  = author;
     Players = players;
     Rules   = rules;
     InteractionController = interactionController;
     Match       = match;
     Score       = score;
     MatchResult = matchResult;
 }
コード例 #19
0
 public MutableBoard(IGameRules gameRules, int width = 10, int heightVisible = 20)
 {
     GameRules     = gameRules;
     Width         = width;
     HeightVisible = heightVisible;
     Height        = heightVisible + 2;
     m_Data        = new TetrominoType[Width * Height];
     for (int i = 0; i < m_Data.Length; ++i)
     {
         m_Data[i] = TetrominoType.Empty;
     }
 }
コード例 #20
0
ファイル: Game.cs プロジェクト: MingStar/SimUniversity
 public Game(IBoard board, int numOfPlayers, IGameRules rules)
 {
     Board = (Board.Board)board; //TODO: remove type casting
     Rules = rules;
     NumberOfUniversities = numOfPlayers;
     ProbabilityWithNoCut = Math.Pow(
         (1 - GameConstants.DiceRollNumber2Chance[7]/GameConstants.Chance.TotalDiceRoll),
         NumberOfUniversities
         );
     CreateUniversities(numOfPlayers);
     Round = 1;
     Reset();
 }
コード例 #21
0
        public GameStateMachine?TryCreateGame(Guid gameId, IGameRules gameRules)
        {
            var game = new GameStateMachine(gameId, gameRules, this);

            if (!gamesById.TryAdd(game.GameId, game))
            {
                return(null);
            }

            gamesByPlayerKey.TryAdd(game.DefenderKey, game);
            gamesByPlayerKey.TryAdd(game.AttackerKey, game);
            return(game);
        }
コード例 #22
0
        public GameServiceTest()
        {
            var serviceProvider = new ServiceCollection()
                                  .AddLogging()
                                  .BuildServiceProvider();
            var factory = serviceProvider.GetService <ILoggerFactory>();

            _logger = factory.CreateLogger <GameService>();

            _repository  = new FakeCardsRepository("GameServiceTestDb");
            _rules       = new FakeGameRules();
            _gameService = new GameService(_repository, _logger, _rules);
        }
コード例 #23
0
        public Game(IGameRules rules, IPlayer player1, IPlayer player2, IHistory history, byte size)
        {
            // remove this intialization
            player1.Figures = new List <IFigure>();
            player2.Figures = new List <IFigure>();

            _history = history;
            Size     = size;
            Rules    = rules;

            Board = new Board(player1, player2, size);
            Rules.PlaceFigures(Board);
        }
コード例 #24
0
 public Trick(
     RoundPlayerInfo firstToPlay,
     RoundPlayerInfo secondToPlay,
     IStateManager stateManager,
     IDeck deck,
     IGameRules gameRules)
 {
     this.firstToPlay  = firstToPlay;
     this.secondToPlay = secondToPlay;
     this.stateManager = stateManager;
     this.deck         = deck;
     this.gameRules    = gameRules;
 }
コード例 #25
0
ファイル: GridHelper.cs プロジェクト: agamya/GameOfLife
 public static IGrid GetNextGenerationGrid(IGrid currentGrid, IGameRules gameRules)
 {
     try
     {
         return new Generation().GetNextGeneration(currentGrid, gameRules);
     }
     catch (Exception e)
     {
         System.Console.WriteLine(e);
         ApplicationLogger.LogException(1, e, LogCategory.Business, TraceEventType.Error);
     }
     return null;
 }
コード例 #26
0
ファイル: Trick.cs プロジェクト: NotDemons/NotDemonsRepo
 public Trick(
     RoundPlayerInfo firstToPlay,
     RoundPlayerInfo secondToPlay,
     IStateManager stateManager,
     IDeck deck,
     IGameRules gameRules)
 {
     this.firstToPlay = firstToPlay;
     this.secondToPlay = secondToPlay;
     this.stateManager = stateManager;
     this.deck = deck;
     this.gameRules = gameRules;
 }
コード例 #27
0
ファイル: Generation.cs プロジェクト: agamya/GameOfLife
 /// <summary>
 ///     By applying game rules get the next genertion grid instance
 /// </summary>
 /// <param name="currentGrid"> Grid on which games rules </param>
 /// <param name="gameRules"> </param>
 /// <returns> Evolved grid instance </returns>
 public IGrid GetNextGeneration(IGrid currentGrid, IGameRules gameRules)
 {
     if (currentGrid != null && gameRules != null)
     {
         var gridCopy = currentGrid.Copy(currentGrid);
         foreach (var cell in currentGrid.GetAllCurrentCellInfo())
         {
             cell.Alive = gameRules.WillBeAliveInNextGeneration(gridCopy, cell);
             gridCopy.MakeCell(cell);
         }
         return gridCopy;
     }
     return null;
 }
コード例 #28
0
ファイル: SimRound.cs プロジェクト: gb-umich/SANTIAGO
        public SimRound(
            ISimPlayer firstPlayer,
            ISimPlayer secondPlayer,
            IGameRules gameRules,
            PlayerPosition firstToPlay = PlayerPosition.FirstPlayer)
        {
            this.gameRules = gameRules;
            this.deck = new SimDeck();
            this.stateManager = new SimStateManager();

            this.firstPlayer = new SimRoundPlayerInfo(firstPlayer);
            this.secondPlayer = new SimRoundPlayerInfo(secondPlayer);

            this.firstToPlay = firstToPlay;
        }
コード例 #29
0
    public GameMaker(int rowCount, int rowWidth, int groundFrom, int groundTo, GameObject player,
                     ILevelGenerator levelGenerator, IGameRules gameRules, IWorldCreator worldCreator)
    {
        _rowCount     = rowCount;
        _rowWidth     = rowWidth;
        _groundFrom   = groundFrom;
        _groundTo     = groundTo;
        _worldCreator = worldCreator;
        _player       = player;

        _levelGenerator = levelGenerator;
        _gameRules      = gameRules;

        Debug.Log("New game, GameMaker constructor.");
    }
コード例 #30
0
        private SemaphoreHost(IGameRules gameRules, IGameResolver gameResolver,
            IEnumerable<IParserPlayer> playersIncome, ILogger logger)
        {
            Logger = logger;
            resolver = gameResolver;

            // init players
            this.players = playersIncome.ToConcurrentQueue(gameRules, gameResolver, mi);

            // devise a game finish condition
            ctSrc = new CancellationTokenSource(gameResolver.MaxMilliseconds);
            ctSrc.Token.Register(CancellationRoutine);

            sem = new SemaphoreSlim(0, 1);
        }
コード例 #31
0
        public Round(
            IPlayer firstPlayer,
            IPlayer secondPlayer,
            IGameRules gameRules,
            PlayerPosition firstToPlay = PlayerPosition.FirstPlayer)
        {
            this.gameRules    = gameRules;
            this.deck         = new Deck();
            this.stateManager = new StateManager();

            this.firstPlayer  = new RoundPlayerInfo(firstPlayer);
            this.secondPlayer = new RoundPlayerInfo(secondPlayer);

            this.firstToPlay = firstToPlay;
        }
コード例 #32
0
        private static void StartGame()
        {
            IPlayer player1 = ChoosePlayerType(1);

            Console.Clear();
            player1.Initialise();
            Console.Clear();
            IPlayer player2 = ChoosePlayerType(2);

            Console.Clear();
            player2.Initialise();
            Console.Clear();
            IGameRules gameRules = GetGameRules(player1, player2);

            Console.WriteLine("Hit any key to begin");
            Console.ReadKey();
            Console.Clear();

            int round = 1;

            while (!gameRules.HasWinner())
            {
                Console.WriteLine($"-----------ROUND {round}------------");
                var player1Move = player1.MakeMove(gameRules);
                Console.WriteLine($"{player1.PlayerName} chose: {player1Move.ChosenOption}");
                var player2Move = player2.MakeMove(gameRules);
                Console.WriteLine($"{player2.PlayerName} chose: {player2Move.ChosenOption}");
                var result = gameRules.GetRoundWinner(player1Move, player2Move);
                if (result.HasWinner)
                {
                    Console.WriteLine($"{result.Winner.PlayerName} is the winner in round {round}");
                }
                else
                {
                    Console.WriteLine($"Round {round} was a draw");
                }
                Console.WriteLine();
                Console.WriteLine("-----CURRENT SCOREBOARD------");
                Console.WriteLine(gameRules.GetCurrentResults());
                Console.WriteLine();
                Console.WriteLine("Hit any key to start the next round");
                Console.ReadKey();
                Console.Clear();
                round++;
            }

            Console.WriteLine($"{gameRules.GetGameWinner().Winner.PlayerName} is the winner!!");
        }
コード例 #33
0
        public Move MakeMove(IGameRules gameRules)
        {
            Move move;

            if (string.IsNullOrWhiteSpace(_lastMove))
            {
                move = GetRandomMove(gameRules);
            }
            else
            {
                move = new Move(this, gameRules.WhatBeats(_lastMove));
            }

            _lastMove = move.ChosenOption;
            return(move);
        }
コード例 #34
0
        public static Player NewPlayer(PlayerType pType, string name, IGameRules rules)
        {
            switch (pType)
            {
            case PlayerType.Random: return(new PlayerRandom(name, rules)); break;

            case PlayerType.Memory: return(new PlayerMemory(name, rules)); break;

            case PlayerType.Thorough: return(new PlayerThorough(name, rules)); break;

            case PlayerType.Cheater: return(new PlayerCheater(name, rules)); break;

            case PlayerType.ThoroughCheater: return(new PlayerThoroughCheater(name, rules)); break;
            }
            return(null);
        }
コード例 #35
0
        public Move MakeMove(IGameRules gameRules)
        {
            var validMoves = gameRules.ValidOptions.ToList();

            OutputMoves(validMoves);

            int chosenMove;

            while (!int.TryParse(ReadInUserInput(), out chosenMove) || validMoves.ElementAtOrDefault(chosenMove - 1) == null)
            {
                OutputGameInfo("You didn't enter a valid move, Try again....");
                OutputMoves(validMoves);
            }

            return(new Move(this, validMoves[chosenMove - 1]));
        }
コード例 #36
0
ファイル: GameForm.cs プロジェクト: ShubArseniy/Millionaire
 Random rand = new Random();        //???
 public GameForm(IDataProvider dataProvider, IGameRules gameRules)
 {
     questionController = new QuestionController(dataProvider, gameRules);
     questionController.RefreshPackNameList();
     InitializeComponent();
     CreateRadio();
     questionController.timer.Tick += new EventHandler(Timer_Tick);
     if (!gameRules.HintsAvailable)
     {
         foreach (Button item in hintsPanel.Controls)
         {
             item.Enabled         = false;
             item.BackgroundImage = ToolStripRenderer.CreateDisabledImage(item.BackgroundImage);
         }
     }
 }
コード例 #37
0
        public SimRound(
            ISimPlayer firstPlayer,
            ISimPlayer secondPlayer,
            IGameRules gameRules,
            IDeck deck,
            ISimStateManager stateManager,
            PlayerPosition firstToPlay = PlayerPosition.FirstPlayer)
        {
            this.gameRules    = gameRules;
            this.deck         = deck;
            this.stateManager = new SimStateManager(); //stateManager;

            this.firstPlayer  = new SimRoundPlayerInfo(firstPlayer);
            this.secondPlayer = new SimRoundPlayerInfo(secondPlayer);

            this.firstToPlay = firstToPlay;
        }
コード例 #38
0
        public DefaultGame(IApp app, IGameBoard board, IPlayer player1, IPlayer player2, IGameRules gameRules)
        {
            if (app == null)
                throw new ArgumentNullException(nameof(app));
            if (player1 == null)
                throw new ArgumentNullException(nameof(player1));
            if (player2 == null)
                throw new ArgumentNullException(nameof(player2));
            if (player1.Equals(player2))
                throw new ArgumentException($"{nameof(player1)} is the same as {nameof(player2)}");
            if (player1.Name == player2.Name)
                throw new ArgumentException(
                    $"{nameof(player1)}.{nameof(player1.Name)} == {nameof(player2)}.{nameof(player2.Name)}");

            this.App = app;
            this.Players = new [] { player1, player2 };

            var reversedBoard = new DefaultBoard(new ReversedLanes(board.Lanes), board.Bar, board.BearedOff);
            this.Boards = new [] { board, reversedBoard };

            this.Rules = gameRules;
        }
コード例 #39
0
ファイル: GameOfLife.cs プロジェクト: agamya/GameOfLife
 public GameOfLife(IGameRules gameRules)
 {
     _gameRules = gameRules;
 }
コード例 #40
0
 public void SetUp()
 {
     rules = new DefaultGameRules();
 }
コード例 #41
0
 public void Uninitialize()
 {
     this.app = null;
     this.gameRules = null;
 }
コード例 #42
0
 public void Initialize(IInitializeContext context)
 {
     this.app = context.App;
     this.gameRules = new DefaultGameRules();
 }
コード例 #43
0
        // TODO: Should last trick winner wins 10 additional points?
        // TODO: What if the total score is 65:65 after giving 10 additional points? Should the player with the last trick win the round?
        public RoundWinnerPoints GetWinnerPoints(
            int firstPlayerPoints,
            int secondPlayerPoints,
            PlayerPosition gameClosedBy,
            PlayerPosition noTricksPlayer,
            IGameRules gameRules)
        {
            if (gameClosedBy == PlayerPosition.FirstPlayer)
            {
                if (firstPlayerPoints < gameRules.RoundPointsForGoingOut)
                {
                    return RoundWinnerPoints.Second(3);
                }
            }

            if (gameClosedBy == PlayerPosition.SecondPlayer)
            {
                if (secondPlayerPoints < gameRules.RoundPointsForGoingOut)
                {
                    return RoundWinnerPoints.First(3);
                }
            }

            if (firstPlayerPoints == secondPlayerPoints)
            {
                // Equal points => 0 points to each
                return RoundWinnerPoints.Draw();
            }

            if (firstPlayerPoints < gameRules.RoundPointsForGoingOut && secondPlayerPoints < gameRules.RoundPointsForGoingOut)
            {
                if (firstPlayerPoints > secondPlayerPoints)
                {
                    return RoundWinnerPoints.First(1);
                }

                if (secondPlayerPoints > firstPlayerPoints)
                {
                    return RoundWinnerPoints.Second(1);
                }
            }

            if (firstPlayerPoints > secondPlayerPoints)
            {
                if (secondPlayerPoints >= gameRules.HalfRoundPoints)
                {
                    return RoundWinnerPoints.First(1);
                }

                if (noTricksPlayer == PlayerPosition.SecondPlayer)
                {
                    return RoundWinnerPoints.First(3);
                }

                // at lest one trick and less than half of the points
                return RoundWinnerPoints.First(2);
            }
            else
            {
                // secondPlayerPoints > firstPlayerPoints
                if (firstPlayerPoints >= gameRules.HalfRoundPoints)
                {
                    return RoundWinnerPoints.Second(1);
                }

                if (noTricksPlayer == PlayerPosition.FirstPlayer)
                {
                    return RoundWinnerPoints.Second(3);
                }

                // at lest one trick and less than half of the points
                return RoundWinnerPoints.Second(2);
            }
        }
コード例 #44
0
 public PlayersTrainerBase(IGameRules rules)
 {
     this.gameManager = new GameManager(rules); ShouldMinimize = false; RequireSingleThreaded = true;
 }
コード例 #45
0
ファイル: PlayersStorage.cs プロジェクト: QuickUnit/PacmanTlv
 public PlayersStorage(IConnectionProvider connectionProvider, IGameRules gameRules)
 {
     _ConnectionProvider = connectionProvider;
     _GameRules = gameRules;
 }
コード例 #46
0
 public ColorPlayerTrainer(IGameRules rules, IPositionPlayer opponent)
     : base(rules)
 {
     gameManager.Player1 = opponent;
 }
コード例 #47
0
 public PositionStepTrainer(IGameRules rules)
     : base(rules)
 {
     gameManager.Player2 = new MeanColorPlayer(this.gameManager.Rules as VanDerWaerdenGameRules);
 }