Ejemplo n.º 1
0
        public override void Perform(Common.Game game)
        {
            int    score   = game.GetScore();
            string handStr = game.Hand.ToString();

            game.PlayHand(_cellId);
            Logger.Log(LogLevel.Debug,
                       "Playing hand: " + handStr + " on cell: " + game.GetCellTypeAt(_cellId).Name + ", score: " + (game.GetScore() - score));
        }
Ejemplo n.º 2
0
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            this.CurrentGame = e.Parameter as Common.Game;
            if (this.CurrentGame == null)
                throw new Exception("Oyun nesnesi null!");

            this.PrepareGameBoard();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            const string defaultGameFilename = "Zork.json";
            string       gameFilename        = (args.Length > 0 ? args[(int)CommandLineArguments.GameFilename] : defaultGameFilename);

            Common.Game game = Common.Game.Load(gameFilename);
            Console.WriteLine("Welcome to Zork");
            game.Run();
            Console.WriteLine("Thank you for playing!");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create a new City & Seek game.
        /// </summary>
        /// <param name="game">Requested game options. Not everything has to be set.</param>
        /// <returns>Created game</returns>
        public async Task <Common.Game> CreateGameAsync(Common.Game game)
        {
            int requestId = RequestId;

            WebSocket.SendAsync(JsonConvert.SerializeObject(new Packet(Intent.CreateGame, game, requestId)), b => { }); // todo: handle error here


            var resp = await AwaitResponse(requestId);

            return(resp.GetPayload <Common.Game>());
        }
Ejemplo n.º 5
0
        public IActionResult Confirm(string gameId, string pieceSquareRef, string endPosition)
        {
            // Called to prompt user to confirm
            var game                 = _gameStore.GetGame(gameId);
            var pieceReference       = (Common.SquareReference)pieceSquareRef;
            var endPositionReference = (Common.SquareReference)endPosition;

            // Move the piece on a copy
            game = new Common.Game(game.Id, game.CurrentTurn, game.Board.MovePiece(pieceReference, endPositionReference), game.Moves.ToList());
            var model = MapToConfirmModel(game, pieceReference, endPositionReference);

            return(View(model));
        }
Ejemplo n.º 6
0
        public override void InitializeAgent()
        {
            Logger.Log(LogLevel.Info, "Initialize Agent");
            _game    = ServiceFactory.GetService <GameService>().CreateNewGame();
            _academy = FindObjectOfType <YahtzeeAcademy>();
            var gamesManager = FindObjectOfType <GamesManager>();

            gamesManager.AddAgent(this);

            _actionTable = new List <GameAction>()
            {
                new GameActionRoll(),
            };

            AddPlayHandActions();
            AddToggleHoldDiceActions();
        }
Ejemplo n.º 7
0
        static void Main(string[] args)
        {
            const string defaultGameFileName = "Zork.json";
            string       gameFileName        = (args.Length > 0 ? args[(int)CommandLineArguments.GameFileName] : defaultGameFileName);

            ConsoleOutputService output = new ConsoleOutputService();
            ConsoleInputService  input  = new ConsoleInputService();

            Common.Game game = Common.Game.Load(gameFileName, output, input);

            while (game.IsRunning)
            {
                output.Write("\n> ");
                input.ProcessInput();
            }

            output.WriteLine("Thank you for playing!");
        }
Ejemplo n.º 8
0
        private GameModel MapToChoosePieceModel(Common.Game game)
        {
            var hasMoves = false;
            var model    = new GameModel
            {
                CurrentPlayer = game.CurrentTurn,
                Opponent      = game.CurrentTurn == Common.Color.Black ? Common.Color.White : Common.Color.Black,
                InCheck       = game.CurrentPlayerInCheck,
                Board         = new Models.Game.Board
                {
                    Squares = game.Board.Squares
                              .Select((row, rowIndex) =>
                                      row.Select((square, columnIndex) =>
                    {
                        // highlight current player's pieces with moves
                        bool canSelect = square.Piece.Color == game.CurrentTurn &&
                                         game.GetAvailableMoves(square.Reference).Any();
                        if (canSelect)
                        {
                            hasMoves = true;
                        }
                        string squareRef = square.Reference.ToString();
                        return(new BoardSquare
                        {
                            PieceImage = ImageNameFromPiece(square.Piece),
                            PieceName = square.Piece.Color + " " + square.Piece.PieceType,
                            SquareColour = SquareColors[(rowIndex + columnIndex) % 2],
                            CanSelect = canSelect,
                            SelectUrl = canSelect
                                                            ? Url.Action(nameof(ChooseEndPosition), new { pieceSquareRef = squareRef })
                                                            : null,
                            ReferenceString = squareRef
                        });
                    })
                                      .ToArray()
                                      ).ToArray()
                },
                MoveHistory = MapToHistoricalMoves(game.Moves)
            };

            model.HasMoves = hasMoves;
            return(model);
        }
Ejemplo n.º 9
0
 private GameModel MapToChooseEndPositionModel(Common.Game game, Common.SquareReference selectedSquareReference)
 {
     Common.SquareReference[] availableMoves = game.GetAvailableMoves(selectedSquareReference).ToArray();
     return(new GameModel
     {
         CurrentPlayer = game.CurrentTurn,
         Opponent = game.CurrentTurn == Common.Color.Black ? Common.Color.White : Common.Color.Black,
         InCheck = game.CurrentPlayerInCheck,
         Board = new Models.Game.Board
         {
             Squares = game.Board.Squares
                       .Select((row, rowIndex) =>
                               row.Select((square, columnIndex) =>
             {
                 bool canSelect = availableMoves.Contains(square.Reference);
                 string squareRef = square.Reference.ToString();
                 string selectUrl = canSelect
                                                     ? Url.Action(nameof(Confirm), new { pieceSquareRef = selectedSquareReference.ToString(), endPosition = squareRef })
                                                     : null;
                 return new BoardSquare
                 {
                     PieceImage = ImageNameFromPiece(square.Piece),
                     PieceName = square.Piece.Color + " " + square.Piece.PieceType,
                     SquareColour = SquareColors[(rowIndex + columnIndex) % 2],
                     CanSelect = canSelect,
                     Reference = square.Reference,
                     SelectUrl = selectUrl,
                     ReferenceString = squareRef
                 };
             })
                               .ToArray()
                               ).ToArray(),
             SelectedSquare = selectedSquareReference
         },
         MoveHistory = MapToHistoricalMoves(game.Moves)
     });
 }
Ejemplo n.º 10
0
 private GameModel MapToConfirmModel(
     Common.Game game,
     Common.SquareReference selectedSquareReference,
     Common.SquareReference endPosition)
 {
     //Common.SquareReference[] availableMoves = game.GetAvailableMoves();
     return(new GameModel
     {
         CurrentPlayer = game.CurrentTurn,
         Opponent = game.CurrentTurn == Common.Color.Black ? Common.Color.White : Common.Color.Black,
         Board = new Models.Game.Board
         {
             Squares = game.Board.Squares
                       .Select((row, rowIndex) =>
                               row.Select((square, columnIndex) =>
             {
                 // highlight any space or opponent piece
                 // TODO add proper available move calculation!!
                 bool canSelect = square.Piece.Color != game.CurrentTurn;
                 string squareRef = square.Reference.ToString();
                 return new BoardSquare
                 {
                     PieceImage = ImageNameFromPiece(square.Piece),
                     PieceName = square.Piece.Color + " " + square.Piece.PieceType,
                     SquareColour = SquareColors[(rowIndex + columnIndex) % 2],
                     CanSelect = false,
                     Reference = square.Reference,
                     ReferenceString = squareRef
                 };
             })
                               .ToArray()
                               ).ToArray(),
             SelectedSquare = selectedSquareReference
         },
         MoveHistory = MapToHistoricalMoves(game.Moves)
     });
 }
Ejemplo n.º 11
0
 public override void AgentReset()
 {
     Logger.Log(LogLevel.Debug, "AgentReset");
     _game = ServiceFactory.GetService <GameService>().CreateNewGame();
 }
Ejemplo n.º 12
0
 public override bool IsValid(Common.Game game)
 {
     return(game.CanPlayInCell(_cellId));
 }
Ejemplo n.º 13
0
 static public HighScore.Game ToPOCO(this Common.Game game)
 {
     return(new HighScore.Game {
         ID = game.ID, Name = game.Name
     });
 }
Ejemplo n.º 14
0
 public virtual int MaximumPossible(Common.Game game)
 {
     return(0);
 }
Ejemplo n.º 15
0
 public virtual int MeanExpectation(Common.Game game)
 {
     return(0);
 }
Ejemplo n.º 16
0
 public override void Perform(Common.Game game)
 {
     game.Roll();
     Logger.Log(LogLevel.Debug, "GameActionRoll, current hand: " + game.Hand.ToString());
 }
 public override void Perform(Common.Game game)
 {
     Logger.Log(LogLevel.Debug, "hand: " + game.Hand.ToString() + "Toggle: " + GetToggleString());
     game.ToggleHand(_toggle);
 }
Ejemplo n.º 18
0
 public override int MeanExpectation(Common.Game game)
 {
     return(game.GetCell(_cellId).MeanExpectation(game.Gameboard));
 }
Ejemplo n.º 19
0
 public GameCreatedEvent(string correlationId, bool isTest, bool isDebug, Common.Game game)
     : base(correlationId, isTest, isDebug, nameof(GameCreatedEvent), 1)
 {
     Game = game;
 }
Ejemplo n.º 20
0
 public GameCreatedEvent(string correlationId, bool isTest, bool isDebug, string eventId, int version, Common.Game game)
     : base(correlationId, isTest, isDebug, nameof(GameCreatedEvent), eventId, version)
 {
     Game = game;
 }
Ejemplo n.º 21
0
 public override int MaximumPossible(Common.Game game)
 {
     return(game.GetCell(_cellId).MaximumPossible(game.Gameboard));
 }
Ejemplo n.º 22
0
 public GameOverEvent(Common.Game game)
 {
     Game = game;
 }
Ejemplo n.º 23
0
 public abstract bool IsValid(Common.Game game);
Ejemplo n.º 24
0
 public abstract void Perform(Common.Game game);
 public override bool IsValid(Common.Game game)
 {
     return(game.CanToggle());
 }
Ejemplo n.º 26
0
 public abstract void Revert(Common.Game game);
 public override void Revert(Common.Game game)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 28
0
 public GameStateUpdateEvent(Common.Game game)
 {
     Game = game;
 }