Skip to content

Commit

Permalink
Merge pull request #1 from siggame/master
Browse files Browse the repository at this point in the history
Updating client
  • Loading branch information
TehPers authored Apr 9, 2017
2 parents 5a8610a + c7a9282 commit 4422997
Show file tree
Hide file tree
Showing 11 changed files with 367 additions and 67 deletions.
66 changes: 66 additions & 0 deletions Games/Stumped/AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,72 @@ public bool RunTurn()
// <<-- /Creer-Merge: runTurn -->>
}

/// <summary>
/// A very basic path finding algorithm (Breadth First Search) that when given a starting Tile, will return a valid path to the goal Tile.
/// </summary>
/// <remarks>
/// This is NOT an optimal pathfinding algorithm. It is intended as a stepping stone if you want to improve it.
/// </remarks>
/// <param name="start">the starting Tile</param>
/// <param name="goal">the goal Tile</param>
/// <returns>A List of Tiles representing the path, the the first element being a valid adjacent Tile to the start, and the last element being the goal. Or an empty list if no path found.</returns>
List<Tile> FindPath(Tile start, Tile goal)
{
// no need to make a path to here...
if (start == goal)
{
return new List<Tile>();
}

// the tiles that will have their neighbors searched for 'goal'
Queue<Tile> fringe = new Queue<Tile>();

// How we got to each tile that went into the fringe.
Dictionary<Tile, Tile> cameFrom = new Dictionary<Tile, Tile>();

// Enqueue start as the first tile to have its neighbors searched.
fringe.Enqueue(start);

// keep exploring neighbors of neighbors... until there are no more.
while (fringe.Count > 0)
{
// the tile we are currently exploring.
Tile inspect = fringe.Dequeue();

// cycle through the tile's neighbors.
foreach (Tile neighbor in inspect.GetNeighbors())
{
if (neighbor == goal)
{
// Follow the path backward starting at the goal and return it.
List<Tile> path = new List<Tile>();
path.Add(goal);

// Starting at the tile we are currently at, insert them retracing our steps till we get to the starting tile
for (Tile step = inspect; step != start; step = cameFrom[step])
{
path.Insert(0, step);
}

return path;
}

// if the tile exists, has not been explored or added to the fringe yet, and it is pathable
if (neighbor != null && !cameFrom.ContainsKey(neighbor) && neighbor.IsPathable())
{
// add it to the tiles to be explored and add where it came from.
fringe.Enqueue(neighbor);
cameFrom.Add(neighbor, inspect);
}

} // foreach(neighbor)

} // while(fringe not empty)

// if you're here, that means that there was not a path to get to where you want to go.
// in that case, we'll just return an empty path.
return new List<Tile>();
}

// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional methods here for your AI to call
Expand Down
49 changes: 25 additions & 24 deletions Games/Stumped/Beaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,37 @@ class Beaver : Stumped.GameObject
{
#region Properties
/// <summary>
/// The number of actions remaining for the beaver this turn.
/// The number of actions remaining for the Beaver this turn.
/// </summary>
public int Actions { get; protected set; }

/// <summary>
/// The number of branches this beaver is holding.
/// The amount of branches this Beaver is holding.
/// </summary>
public int Branches { get; protected set; }

/// <summary>
/// The number of fish this beaver is holding.
/// The amount of food this Beaver is holding.
/// </summary>
public int Fish { get; protected set; }
public int Food { get; protected set; }

/// <summary>
/// How much health this beaver has left.
/// How much health this Beaver has left.
/// </summary>
public int Health { get; protected set; }

/// <summary>
/// The Job this beaver was recruited to do.
/// The Job this Beaver was recruited to do.
/// </summary>
public Stumped.Job Job { get; protected set; }

/// <summary>
/// How many moves this beaver has left this turn.
/// How many moves this Beaver has left this turn.
/// </summary>
public int Moves { get; protected set; }

/// <summary>
/// The Player that owns and can control this beaver.
/// The Player that owns and can control this Beaver.
/// </summary>
public Stumped.Player Owner { get; protected set; }

Expand All @@ -61,12 +61,12 @@ class Beaver : Stumped.GameObject
public bool Recruited { get; protected set; }

/// <summary>
/// The tile this beaver is on.
/// The Tile this Beaver is on.
/// </summary>
public Stumped.Tile Tile { get; protected set; }

/// <summary>
/// Number of turns this beaver is distracted for (0 means not distracted).
/// Number of turns this Beaver is distracted for (0 means not distracted).
/// </summary>
public int TurnsDistracted { get; protected set; }

Expand All @@ -88,7 +88,7 @@ protected Beaver() : base()
/// <summary>
/// Attacks another adjacent beaver.
/// </summary>
/// <param name="beaver">The beaver to attack. Must be on an adjacent tile.</param>
/// <param name="beaver">The Beaver to attack. Must be on an adjacent Tile.</param>
/// <returns>True if successfully attacked, false otherwise.</returns>
public bool Attack(Stumped.Beaver beaver)
{
Expand All @@ -98,7 +98,7 @@ public bool Attack(Stumped.Beaver beaver)
}

/// <summary>
/// Builds a lodge on the Beavers current tile.
/// Builds a lodge on the Beavers current Tile.
/// </summary>
/// <returns>True if successfully built a lodge, false otherwise.</returns>
public bool BuildLodge()
Expand All @@ -108,11 +108,11 @@ public bool BuildLodge()
}

/// <summary>
/// Drops some of the given resource on the beaver's tile. Fish dropped in water disappear instantly, and fish dropped on land die one per tile per turn.
/// Drops some of the given resource on the beaver's Tile.
/// </summary>
/// <param name="tile">The Tile to drop branches/fish on. Must be the same Tile that the Beaver is on, or an adjacent one.</param>
/// <param name="resource">The type of resource to drop ('branch' or 'fish').</param>
/// <param name="amount">The amount of the resource to drop, numbers <= 0 will drop all the resource type.</param>
/// <param name="tile">The Tile to drop branches/food on. Must be the same Tile that the Beaver is on, or an adjacent one.</param>
/// <param name="resource">The type of resource to drop ('branch' or 'food').</param>
/// <param name="amount">The amount of the resource to drop, numbers &lt;= 0 will drop all the resource type.</param>
/// <returns>True if successfully dropped the resource, false otherwise.</returns>
public bool Drop(Stumped.Tile tile, string resource, int amount=0)
{
Expand All @@ -124,9 +124,9 @@ public bool Drop(Stumped.Tile tile, string resource, int amount=0)
}

/// <summary>
/// Harvests the branches or fish from a Spawner on an adjacent tile.
/// Harvests the branches or food from a Spawner on an adjacent Tile.
/// </summary>
/// <param name="spawner">The Spawner you want to harvest. Must be on an adjacent tile.</param>
/// <param name="spawner">The Spawner you want to harvest. Must be on an adjacent Tile.</param>
/// <returns>True if successfully harvested, false otherwise.</returns>
public bool Harvest(Stumped.Spawner spawner)
{
Expand All @@ -136,9 +136,9 @@ public bool Harvest(Stumped.Spawner spawner)
}

/// <summary>
/// Moves this beaver from its current tile to an adjacent tile.
/// Moves this Beaver from its current Tile to an adjacent Tile.
/// </summary>
/// <param name="tile">The tile this beaver should move to.</param>
/// <param name="tile">The Tile this Beaver should move to.</param>
/// <returns>True if the move worked, false otherwise.</returns>
public bool Move(Stumped.Tile tile)
{
Expand All @@ -148,11 +148,11 @@ public bool Move(Stumped.Tile tile)
}

/// <summary>
/// Picks up some branches or fish on the beaver's tile.
/// Picks up some branches or food on the beaver's tile.
/// </summary>
/// <param name="tile">The Tile to pickup branches/fish from. Must be the same Tile that the Beaver is on, or an adjacent one.</param>
/// <param name="resource">The type of resource to pickup ('branch' or 'fish').</param>
/// <param name="amount">The amount of the resource to drop, numbers <= 0 will pickup all of the resource type.</param>
/// <param name="tile">The Tile to pickup branches/food from. Must be the same Tile that the Beaver is on, or an adjacent one.</param>
/// <param name="resource">The type of resource to pickup ('branch' or 'food').</param>
/// <param name="amount">The amount of the resource to drop, numbers &lt;= 0 will pickup all of the resource type.</param>
/// <returns>True if successfully picked up a resource, false otherwise.</returns>
public bool Pickup(Stumped.Tile tile, string resource, int amount=0)
{
Expand All @@ -164,6 +164,7 @@ public bool Pickup(Stumped.Tile tile, string resource, int amount=0)
}



// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional method(s) here.
// <<-- /Creer-Merge: methods -->>
Expand Down
32 changes: 22 additions & 10 deletions Games/Stumped/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ class Game : BaseGame
/// </summary>
public IList<Stumped.Beaver> Beavers { get; protected set; }

/// <summary>
/// How many branches a lodge must have to be considered complete.
/// </summary>
public int BranchesToCompleteLodge { get; protected set; }

/// <summary>
/// The player whose turn it is currently. That player can send commands. Other players cannot.
/// </summary>
Expand All @@ -41,7 +36,7 @@ class Game : BaseGame
public int CurrentTurn { get; protected set; }

/// <summary>
/// When a Player has less Beavers than this number, recruiting other Beavers is free.
/// When a Player has less Beavers than this number, then recruiting other Beavers is free.
/// </summary>
public int FreeBeaversCount { get; protected set; }

Expand All @@ -56,9 +51,9 @@ class Game : BaseGame
public double LodgeCostConstant { get; protected set; }

/// <summary>
/// How many lodges must be complete at once to win the game.
/// How many lodges must be owned by a Player at once to win the game.
/// </summary>
public int LodgesCompleteToWin { get; protected set; }
public int LodgesToWin { get; protected set; }

/// <summary>
/// The number of Tiles in the map along the y (vertical) axis.
Expand Down Expand Up @@ -91,12 +86,12 @@ class Game : BaseGame
public IList<Stumped.Spawner> Spawner { get; protected set; }

/// <summary>
/// Constant number used to calculate how many breanches/fish Beavers harvest from spawners.
/// Constant number used to calculate how many branches/food Beavers harvest from Spawners.
/// </summary>
public double SpawnerHarvestConstant { get; protected set; }

/// <summary>
/// All the types of spawners in the game.
/// All the types of Spawners in the game.
/// </summary>
public IList<string> SpawnerTypes { get; protected set; }

Expand Down Expand Up @@ -129,6 +124,23 @@ protected Game() : base()
}


/// <summary>
/// Gets the Tile at a specified (x, y) position
/// </summary>
/// <param name="x">integer between 0 and the MapWidth</param>
/// <param name="y">integer between 0 and the MapHeight</param>
/// <returns>the Tile at (x, y) or null if out of bounds</returns>
public Tile GetTileAt(int x, int y)
{
if (x < 0 || y < 0 || x >= this.MapWidth || y >= this.MapHeight)
{
// out of bounds
return null;
}

return this.Tiles[x + y * this.MapWidth];
}

// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional method(s) here.
// <<-- /Creer-Merge: methods -->>
Expand Down
1 change: 1 addition & 0 deletions Games/Stumped/GameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void Log(string message)
}



// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional method(s) here.
// <<-- /Creer-Merge: methods -->>
Expand Down
27 changes: 14 additions & 13 deletions Games/Stumped/Job.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,52 +21,52 @@ class Job : Stumped.GameObject
{
#region Properties
/// <summary>
/// The number of actions this job can make per turn.
/// The number of actions this Job can make per turn.
/// </summary>
public int Actions { get; protected set; }

/// <summary>
/// How many resources a beaver with this job can hold at once.
/// How many combined resources a beaver with this Job can hold at once.
/// </summary>
public int CarryLimit { get; protected set; }

/// <summary>
/// Scalar for how many branches this job harvests at once.
/// Scalar for how many branches this Job harvests at once.
/// </summary>
public int Chopping { get; protected set; }

/// <summary>
/// How many fish this Job costs to recruit.
/// How much food this Job costs to recruit.
/// </summary>
public int Cost { get; protected set; }

/// <summary>
/// The amount of damage this job does per attack.
/// The amount of damage this Job does per attack.
/// </summary>
public int Damage { get; protected set; }

/// <summary>
/// How many turns a beaver attacked by this job is distracted by.
/// How many turns a beaver attacked by this Job is distracted by.
/// </summary>
public int DistractionPower { get; protected set; }

/// <summary>
/// Scalar for how many fish this job harvests at once.
/// The amount of starting health this Job has.
/// </summary>
public int Fishing { get; protected set; }
public int Health { get; protected set; }

/// <summary>
/// The amount of starting health this job has.
/// The number of moves this Job can make per turn.
/// </summary>
public int Health { get; protected set; }
public int Moves { get; protected set; }

/// <summary>
/// The number of moves this job can make per turn.
/// Scalar for how much food this Job harvests at once.
/// </summary>
public int Moves { get; protected set; }
public int Munching { get; protected set; }

/// <summary>
/// The job title ('builder', 'fisher', etc).
/// The Job title.
/// </summary>
public string Title { get; protected set; }

Expand Down Expand Up @@ -98,6 +98,7 @@ public Stumped.Beaver Recruit(Stumped.Tile tile)
}



// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional method(s) here.
// <<-- /Creer-Merge: methods -->>
Expand Down
5 changes: 3 additions & 2 deletions Games/Stumped/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Player : Stumped.GameObject
public IList<Stumped.Beaver> Beavers { get; protected set; }

/// <summary>
/// How many branches are required to build a lodge for this player.
/// How many branches are required to build a lodge for this Player.
/// </summary>
public int BranchesToBuildLodge { get; protected set; }

Expand All @@ -36,7 +36,7 @@ class Player : Stumped.GameObject
public string ClientType { get; protected set; }

/// <summary>
/// A list of tiles that contain lodges owned by this player.
/// A list of Tiles that contain lodges owned by this player.
/// </summary>
public IList<Stumped.Tile> Lodges { get; protected set; }

Expand Down Expand Up @@ -93,6 +93,7 @@ protected Player() : base()
}



// <<-- Creer-Merge: methods -->> - Code you add between this comment and the end comment will be preserved between Creer re-runs.
// you can add additional method(s) here.
// <<-- /Creer-Merge: methods -->>
Expand Down
Loading

0 comments on commit 4422997

Please sign in to comment.