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)); }
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(); }
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!"); }
/// <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>()); }
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)); }
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(); }
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!"); }
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); }
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) }); }
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) }); }
public override void AgentReset() { Logger.Log(LogLevel.Debug, "AgentReset"); _game = ServiceFactory.GetService <GameService>().CreateNewGame(); }
public override bool IsValid(Common.Game game) { return(game.CanPlayInCell(_cellId)); }
static public HighScore.Game ToPOCO(this Common.Game game) { return(new HighScore.Game { ID = game.ID, Name = game.Name }); }
public virtual int MaximumPossible(Common.Game game) { return(0); }
public virtual int MeanExpectation(Common.Game game) { return(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); }
public override int MeanExpectation(Common.Game game) { return(game.GetCell(_cellId).MeanExpectation(game.Gameboard)); }
public GameCreatedEvent(string correlationId, bool isTest, bool isDebug, Common.Game game) : base(correlationId, isTest, isDebug, nameof(GameCreatedEvent), 1) { Game = game; }
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; }
public override int MaximumPossible(Common.Game game) { return(game.GetCell(_cellId).MaximumPossible(game.Gameboard)); }
public GameOverEvent(Common.Game game) { Game = game; }
public abstract bool IsValid(Common.Game game);
public abstract void Perform(Common.Game game);
public override bool IsValid(Common.Game game) { return(game.CanToggle()); }
public abstract void Revert(Common.Game game);
public override void Revert(Common.Game game) { throw new System.NotImplementedException(); }
public GameStateUpdateEvent(Common.Game game) { Game = game; }