public override void TakeTurn(IBoardGame gameBoard) { if (!this.CanTakeTurn) { return; } // hard code in specific abilities depending on the monster var cleanupTurn = new CleanupTurn(this); cleanupTurn.Cleanup(); // simply attack right now var humanPlayers = gameBoard.GetHumanPlayers().ToList(); var humanToAttack = new RandomPlayer().TargetPlayer(humanPlayers); if (humanToAttack < 0) { return; } var humanPlayer = humanPlayers[humanToAttack]; var attackAmount = new StaticAmount().AttackAmount(); var attackParameters = new AttackParameters { AdjustedAmount = attackAmount, OriginalAmount = attackAmount, PlayerAttacking = this, PlayerBeingAttacked = humanPlayer }; humanPlayer.TakeDamage(gameBoard, attackParameters); GameLogger.LogFormat("{0} gave {1} damage to {2}", this.Name, attackAmount, attackParameters.ReportPlayersBeingAttacked()); }
public MCTSPlayer(IBoardGame <TGameState> game, double confidenceCoef, TimeSpan simulationTimeLimit) { Game = game; ConfidenceCoef = confidenceCoef; SimulationTimeLimit = simulationTimeLimit; Statistics = new Dictionary <TGameState, StatisticsRecord>(); }
public AttackCard(HumanPlayer player, IBoardGame gameBoard, ITargetPlayer targetPlayer, IAttackAmount attackAmount) { this.player = player; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; this.attackAmount = attackAmount; }
public override void DrawCard(IBoardGame gameBoard) { if (CurrentCards.Count > 4) { GameLogger.LogFormat("{0} drew no cards because they have {1} already.", this.Name, this.CurrentCards.Count); return; } var iter = 0; while (this.CurrentCards.Count < 5 && iter < 5) { // select from the list of cards to draw from if (this.CardsToDrawFrom.Any()) { var randCardIdx = Randomizer.GetRandomValue(0, this.CardsToDrawFrom.Count - 1); var firstCard = this.CardsToDrawFrom[randCardIdx]; GameLogger.LogFormat("{0} drew {1}.", this.Name, firstCard.Name); this.CurrentCards.Add(firstCard); } else { // reshuffle foreach (var card in this.DrawnCards) { this.CardsToDrawFrom.Add(card); } this.DrawnCards.Clear(); } iter++; } }
void Awake() { Debug.Log("AREngine Starting up.."); arRaycastManager = GetComponent <ARRaycastManager>(); touchPosition = default; boardGame = Game.CURRENTGAMEMETADATA.GetBoardGame(); boardPlaced = false; Debug.Log("AREngine Online"); }
public override void Initialize(IBoardGame gameBoard) { for (var i = 0; i < 4; i++) { var card = new DrainLife(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 6; i++) { var card = new MagicMissile(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 6; i++) { var card = new DragonFlame(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 3; i++) { var card = new FrostBolt(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 6; i++) { var card = new SurefireShot(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 3; i++) { var card = new LightningBolt(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 6; i++) { var card = new ColdSnap(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 1; i++) { var card = new FireBall(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } for (var i = 0; i < 1; i++) { var card = new BallOfForce(this, gameBoard, new LowestHpPlayer()); this.CardsToDrawFrom.Add(card); } }
public BoardEngine( IGameSettings gameSettings, IBoardGame boardGame, IPlayer player1, IPlayer player2) { _gameSettings = gameSettings; _boardGame = boardGame; _player1 = player1; _player2 = player2; }
public override Move <ConnectFourToken> GetNextMove(IBoardGame <ConnectFourToken> game) { string input; Move <ConnectFourToken> move; do { Console.Write($"Player {this}, enter a column number [{1}, {game.Width}]: "); input = Console.ReadLine(); }while (!int.TryParse(input, out int result) || !game.IsMoveAllowed(move = new Move <ConnectFourToken>(this, new Coordinate(result, 1)))); return(move); }
private void startGame(String name) { // end any games that may have been running endGameThread(); prepareRenderPanel(); IBoardGame myGame = gamePool.getGame(name); myGame.setRenderSurface(renderPanel); // make and start a new thread gamethread = new Thread(new ThreadStart(myGame.gameLoop)); gamethread.Start(); }
/** * */ public bool loadPlugins(String argDirectory, out Dictionary <String, IBoardGame> argCollection) { // make the collection class we want to set as our out parameter Dictionary <String, IBoardGame> plugins = new Dictionary <String, IBoardGame>(); bool success = true; // log it Logger.log("PluginLoader: Loading plugins...", LEVEL.DEBUG); try { // try to obtain a list of all plugins, this may throw an exception List <String> paths = getAllPlugins(argDirectory); // if there are no plugins present... if (paths.Count == 0) { Logger.log("PluginLoader: Warning - no plugins found", LEVEL.WARNING); } // for all plugin paths in the list... foreach (String path in paths) { // load the game from the path IBoardGame game = loadGameFromDll(path); // check we didnt obtain a null pointer if (game != null) { // add the plugin to our collection plugins.Add(game.getName(), game); // log it Logger.log("PluginLoader: Loaded: " + game.getName() + " [game version " + game.getGameVersion() + ", engine version " + game.getEngineVersion() + "]", LEVEL.DEBUG); } } } catch (System.IO.DirectoryNotFoundException) { // we cannot find a plugins directory // log it and return false Logger.log("PluginLoader: Error - plugin directory not found", LEVEL.ERROR); success = false; } // assing the out parameter argCollection = plugins; return(success); }
public override void TakeDamage(IBoardGame gameBoard, AttackParameters attackParameters) { var humanPlayers = gameBoard.GetHumanPlayers(); // all of them will play defensive cards foreach (var humanPlayer in humanPlayers) { var defensiveInstant = humanPlayer.CurrentCards.FirstOrDefault(card => card.IsDefensiveInstant); if (defensiveInstant != null && !humanPlayer.UsedInstantCard && defensiveInstant.CanUse(attackParameters)) { defensiveInstant.Use(attackParameters); humanPlayer.CurrentCards.Remove(defensiveInstant); } } // we'll take damage here base.TakeDamage(gameBoard, attackParameters); }
public override Move <ConnectFourToken> GetNextMove(IBoardGame <ConnectFourToken> game) { ConnectFourGame clone = (ConnectFourGame)game.Clone(); (Move <ConnectFourToken> nextMove, int _) = Minimax( moveAndPosition: (Move <ConnectFourToken> .Default, clone), depth: MinimaxDepth, alpha: int.MinValue, beta: int.MaxValue, currentPlayer: clone.CurrentPlayer, maximizingCurrentPlayer: true); if (!game.IsMoveAllowed(nextMove)) { throw new InvalidOperationException(); } return(nextMove); }
public IMove ABNegamax(IBoardGame game, int maxDepth, int currentDepth, double alfa, double beta) { if (maxDepth == currentDepth || game.GameIsOver()) return game.EvaluatePosition(); IMove bestMove = null; var moves = (new RandomList<IMove>(game.GetLegalMoves())).Randomize(); foreach (var validMove in moves) { if (bestMove == null) bestMove = validMove; IBoardGame testGame = game.TestMove(validMove); validMove.SetMoveScore(-(ABNegamax(testGame, maxDepth, currentDepth + 1, -beta, -Math.Max(alfa, bestMove.GetMoveScore())).GetMoveScore())); if (validMove.GetMoveScore() > bestMove.GetMoveScore()) { bestMove = validMove; } if (bestMove.GetMoveScore() >= beta) return bestMove; } return bestMove; }
public IMove AdaptiveABNegamax(IBoardGame game, int maxDepth, int currentDepth, double alfa, double beta, List<IMove> opponentsList, IMove opponentsMove) { List<IMove> rankedMoveList = EvaluateMoves(game, maxDepth, 0, alfa, beta); int rank = 0; for (int index = 0; index < opponentsList.Count; index++) { if (!opponentsList[index].IsEqual(opponentsMove)) continue; else { rank = index; break; } } if (rank < rankedMoveList.Count) { while (rank >= 0 && rankedMoveList[rank].GetMoveScore() < 0) { rank--; } if (rank >= 0) return rankedMoveList[rank]; else return rankedMoveList[0]; } else { rank = rankedMoveList.Count - 1; while (rank >= 0 && rankedMoveList[rank].GetMoveScore() < 0) { rank--; } if (rank >= 0) return rankedMoveList[rank]; else return rankedMoveList[0]; } }
/** */ private IBoardGame loadGameFromDll(String path) { IBoardGame myGame = null; // load the assembly Assembly myAs = Assembly.LoadFrom(path); // for all the types in this assembly foreach (Type t in myAs.GetTypes()) { // make sure the type is a non-abstract class, visible and implements our interface if (t.IsClass && !t.IsAbstract && t.IsVisible && (t.GetInterface("BoardSoup.Interface.IBoardGame", true) == typeof(IBoardGame))) { // instantiate the class try { object obj = myAs.CreateInstance(t.FullName); // if it is an implementation of our board game interface... if (obj is IBoardGame) { // log debut output Logger.log("PluginLoader: Loading: " + t.FullName + " from " + t.Module, LEVEL.DEBUG); // cast our class to a board game myGame = (IBoardGame)obj; } } catch (Exception e) { System.Console.WriteLine("-------------------------------"); System.Console.WriteLine("Error loading " + t.FullName + " see: " + e.StackTrace); System.Console.WriteLine("-------------------------------"); } } } return(myGame); }
public abstract Move <TToken> GetNextMove(IBoardGame <TToken> game);
public SwordAttack(Warrior warriorPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.warriorPlayer = warriorPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public BoardGameController(IBoardGame boardGameService, IMapper mapper) { _boardGameService = boardGameService; }
public FireBall(Wizard wizardPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.wizardPlayer = wizardPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public BallOfForce(Wizard wizardPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.wizardPlayer = wizardPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public Remember(Warrior warriorPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.warriorPlayer = warriorPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public override Move <TicTacToeToken> GetNextMove(IBoardGame <TicTacToeToken> game) { return(GetNextMove((TicTacToeGame)game)); }
public ShieldBlock(Warrior warriorPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.warriorPlayer = warriorPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public DefensiveBarrier(Wizard wizardPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.wizardPlayer = wizardPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public Consecrate(Cleric clericPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.clericPlayer = clericPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public RejuvenatingStrike(Warrior warriorPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.warriorPlayer = warriorPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public SteadyAim(Archer archerPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.archerPlayer = archerPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
/// <summary> /// Gets all fields of the given board that the card on the given board field can be moved to. /// </summary> /// <param name="game"></param> /// <param name="field"></param> /// <returns></returns> /// <remarks>AiBase classes can call this on themselves since they implement IBoardGame.</remarks> public static List <BoardField> GetMoveTargetFields(IBoardGame game, BoardField field) { var fields = new List <BoardField>(); var card = field?.Card as OnlineCard; // Firewall card cannot be moved directly to another field if (card == null || card.Owner == null) { return(fields); } // No move possible if it is the turn of the other player if (card.Owner.PlayerNumber == 1 && game.Phase == GamePhase.Player2Turn || card.Owner.PlayerNumber == 2 && game.Phase == GamePhase.Player1Turn) { return(fields); } var x = field.X; var y = field.Y; // Code was written for single player mode. // In online play, the board is flipped for player 2 // We cannot transform the coordinates here or everything will be screwed up // Therefore we just invert the player number var currentPlayer = game.Phase == GamePhase.Player1Turn ? 1 : 2; int opponent = game.Phase == GamePhase.Player1Turn ? 2 : 1; #region Deployment // THIS CODE IS NOT NEEDED ANYMORE. JUST HERE FOR REFERENCE //if (game.Phase == GamePhase.Deployment) //{ // // In this phase you can only move cards between stack and deployment fields. // var owner = card.Owner.PlayerNumber; // var depFields = new BoardField[16]; // var y1 = owner == 1 ? 0 : 7; // var y2 = owner == 1 ? 1 : 6; // var y3 = owner == 1 ? 8 : 9; // for (int ix = 0; ix<=7; ++ix) // { // // Set deployment fields // if (ix == 3 || ix == 4) // depFields[ix] = game.Board[ix, y2]; // else // depFields[ix] = game.Board[ix, y1]; // // Set stack fields // depFields[ix+8] = game.Board[ix, y3]; // } // // Select all fields that have no card // fields.AddRange(depFields.Where(o => o.Card == null)); //} #endregion if (game.Phase == GamePhase.Player1Turn || game.Phase == GamePhase.Player2Turn) { // without boost there are 4 possible locations var fs = new BoardField[4]; if (y > 0 && y <= 7) // Down { fs[0] = game.Board[x, y - 1]; } else { // Special case for exit fields: if (y == 0 && field.IsExit && currentPlayer == 2) { fs[0] = game.Board[4, 10]; } } if (y >= 0 && y < 7) // Up { fs[1] = game.Board[x, y + 1]; } else { // Special case for exit fields: if (y == 7 && field.IsExit && currentPlayer == 1) { fs[1] = game.Board[5, 10]; } } if (x > 0 && x <= 7 && y <= 7) // Left; Mask out stack fields { fs[2] = game.Board[x - 1, y]; } if (x >= 0 && x < 7 && y <= 7) // Right { fs[3] = game.Board[x + 1, y]; } // Moves on opponents cards are allowed, move on own card not for (int i = 0; i < 4; ++i) { if (fs[i] == null) { continue; } if (fs[i].Card != null && fs[i].Card.Owner.PlayerNumber == currentPlayer) { continue; } if (fs[i].Card != null && !(fs[i].Card is OnlineCard)) { continue; // Can only jump on online cards <- This ignores the firewall card } if (fs[i].IsStack) { continue; } if (fs[i].IsExit) { // Exit field is allowed, but only your opponents if (currentPlayer == 1 && fs[i].Y == 0) { continue; } if (currentPlayer == 2 && fs[i].Y == 7) { continue; } } fields.Add(fs[i]); } // Boost can add additional fields if (card.HasBoost) { // The same checks as above apply for all fields var additionalfields = new List <BoardField>(); foreach (var f in fields) { // Ignore field if it has an opponents card if (f.Card != null) { continue; } fs = new BoardField[4]; x = f.X; y = f.Y; if (y > 0 && y <= 7) { fs[0] = game.Board[x, y - 1]; } else { // Special case for exit fields: if (y == 0 && f.IsExit && currentPlayer == 2) { fs[0] = game.Board[4, 10]; } } if (y >= 0 && y < 7) { fs[1] = game.Board[x, y + 1]; } else { // Special case for exit fields: if (y == 7 && f.IsExit && currentPlayer == 1) { fs[1] = game.Board[5, 10]; } } if (x > 0 && x <= 7 && y <= 7) // No Stack fields! { fs[2] = game.Board[x - 1, y]; } if (x >= 0 && x < 7 && y <= 7) // No Stack fields! { fs[3] = game.Board[x + 1, y]; } for (int i = 0; i < 4; ++i) { if (fs[i] == null) { continue; } if (fs[i].Card != null && fs[i].Card.Owner.PlayerNumber == currentPlayer) { continue; } if (fs[i].Card != null && !(fs[i].Card is OnlineCard)) { continue; // Can only jump on online cards <- This ignores the firewall card } if (fs[i].IsStack) { continue; } if (fs[i].IsExit) { // Exit field is allowed, but only your opponents if (currentPlayer == 1 && fs[i].Y == 0) { continue; } if (currentPlayer == 2 && fs[i].Y == 7) { continue; } } additionalfields.Add(fs[i]); } } foreach (var f in additionalfields) { if (!fields.Contains(f)) { fields.Add(f); } } } } return(fields); }
public VampiricDagger(Thief thiefPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.thiefPlayer = thiefPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public FireArrow(Archer archerPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.archerPlayer = archerPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public TwinStrike(Archer archerPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.archerPlayer = archerPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public static int GetWinnerId <TGameState>(this IBoardGame <TGameState> game) where TGameState : IGameState => game.CurrentState.GetWinnerId();
public SurefireShot(Wizard wizardPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.wizardPlayer = wizardPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public Recall(Cleric clericPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.clericPlayer = clericPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public RainofDaggers(Thief thiefPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.thiefPlayer = thiefPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public PerfectShot(Archer archerPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.archerPlayer = archerPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public SpellBuff(Wizard wizardPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.wizardPlayer = wizardPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public override void TakeTurn(IBoardGame gameBoard) { if (!this.CanTakeTurn) { return; } // perform discard cards var discardCards = new DiscardCards(this); discardCards.Discard(); // perform draw this.DrawCard(gameBoard); if (this.CurrentCards.Any()) { // use a card that's not defensive var nonDefensiveInstantCards = this.CurrentCards.Where(card1 => !card1.IsDefensiveInstant).ToList(); var randCardIdx = Randomizer.GetRandomValue(0, nonDefensiveInstantCards.Count() - 1); var card = nonDefensiveInstantCards.ElementAt(randCardIdx); card.Use(); this.CurrentCards.RemoveAt(randCardIdx); } // cleanup var cleanupTurn = new CleanupTurn(this); cleanupTurn.Cleanup(); }
public Riposte(Thief thiefPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.thiefPlayer = thiefPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public virtual void DrawCard(IBoardGame gameBoard) { }
public MagicDefense(Warrior warriorPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.warriorPlayer = warriorPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public virtual void Initialize(IBoardGame gameBoard) { }
public HolyPillar(Cleric clericPlayer, IBoardGame gameBoard, ITargetPlayer targetPlayer) { this.clericPlayer = clericPlayer; this.gameBoard = gameBoard; this.targetPlayer = targetPlayer; }
public static bool IsEnded <TGameState>(this IBoardGame <TGameState> game) where TGameState : IGameState => game.CurrentState.IsTerminal();