1
0
forked from s425077/PotatoPlan

Merge branch 'dev' of s425077/PotatoPlan into master

This commit is contained in:
Oskar Nastały 2020-05-04 00:00:00 +00:00 committed by Gogs
commit a25e05cc3c
92 changed files with 1810 additions and 223220 deletions

View File

@ -44,6 +44,30 @@
/processorParam:TextureFormat=Color
/build:house.png
#begin Markers.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Markers.png
#begin Mountain.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Mountain.png
#begin Plantable.png
/importer:TextureImporter
/processor:TextureProcessor

View File

Before

Width:  |  Height:  |  Size: 3.6 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

BIN
Game1/Content/Markers.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 578 B

BIN
Game1/Content/Mountain.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

View File

Before

Width:  |  Height:  |  Size: 776 B

After

Width:  |  Height:  |  Size: 776 B

View File

Before

Width:  |  Height:  |  Size: 3.9 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

Before

Width:  |  Height:  |  Size: 828 B

After

Width:  |  Height:  |  Size: 828 B

BIN
Game1/Content/Tractor.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.2 KiB

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 1.8 KiB

144
Game1/Game1.cs Normal file
View File

@ -0,0 +1,144 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Game1
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont Bold;
private Texture2D[] tile = new Texture2D[5];
private Texture2D tractor;
private Texture2D house;
private Texture2D markers;
private Tractor tractorUnit = new Tractor();
private Input input = new Input();
private House houseUnit = new House();
private Vector2 mousePosition;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
//Generates the map with some random values
input.init(graphics, new Vector2(16,16), 56, 1); //Generates the starting size
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
tractorUnit.init(houseUnit.GetRectangle(), input); //Generates the Tractor
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the first Size of the Tractor
tractorUnit.setPos(houseUnit.getVector()); //Changes the position of the tractor to the houses position at the start
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 125;
graphics.ApplyChanges();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
//Loads the PNG content and Fonts
tile[0] = Content.Load<Texture2D>("Mountain");
tile[1] = Content.Load<Texture2D>("tileunplantable");
tile[2] = Content.Load<Texture2D>("Plantable");
tile[3] = Content.Load<Texture2D>("Planted");
tile[4] = Content.Load<Texture2D>("Crop");
tractor = Content.Load<Texture2D>("Tractor");
Bold = Content.Load<SpriteFont>("Font");
house = Content.Load<Texture2D>("house");
markers = Content.Load<Texture2D>("Markers");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime) //updates every 60 seconds
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
MouseState state = Mouse.GetState();
mousePosition = new Vector2(state.X, state.Y);
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the size
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the Simulation Speed
tractorUnit.setTractorSpeed(input.changeTractorSpeed(tractorUnit.getTractorSpeed(), tractorUnit.getPos())); //Updates the Tractor Speed
input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles
houseUnit.updateRectangle(input.getSize(), input.getTileSize(), input.getSpacing()); //Updates the position of the house if the house appears out of bound
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) //Draw Function
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for(int i = 0; i < input.getSize().X; i++) //Draw the tiles
{
for (int j = 0; j < input.getSize().Y; j++)
{
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).Status], new Rectangle(i * (input.getSpacingTile()), j * (input.getSpacingTile()), input.getTileSize(), input.getTileSize()), Color.White);
}
}
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getTargetPosition().X / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, (int)tractorUnit.getTargetPosition().Y / input.getSpacingTile() * (input.getTileSize() + input.getSpacing()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green);
for (int i = 0; i < tractorUnit.getPath().getCount() + 1; i++)
{
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getByIndex(i).getCords().X * (input.getSpacingTile()) + input.getTileSize() / 4, (int)tractorUnit.getPath().getByIndex(i).getCords().Y * (input.getSpacingTile()) + input.getTileSize() / 4, input.getTileSize()/2, input.getTileSize()/2), Color.Green);
}
spriteBatch.Draw(house, houseUnit.GetRectangle(), Color.White);
spriteBatch.Draw(markers, new Rectangle((int)tractorUnit.getPath().getFinalDest().getCords().X * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), (int)tractorUnit.getPath().getFinalDest().getCords().Y * (input.getSpacingTile()) + Convert.ToInt32(input.getTileSize() / 6), Convert.ToInt32(input.getTileSize() / 1.5), Convert.ToInt32(input.getTileSize() / 1.5)), Color.Red); //Draws the current target of the tractor
spriteBatch.Draw(tractor, new Vector2((int)tractorUnit.getPos().X + input.getTileSize() / 2, (int)tractorUnit.getPos().Y + input.getTileSize() / 2), new Rectangle(0, 0, input.getTileSize(), input.getTileSize()), Color.White, tractorUnit.getRotation(), new Vector2(input.getTileSize() / 2, input.getTileSize() / 2), 1.0f, SpriteEffects.None, 1);
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20) , Color.White); //Draws the speed value
spriteBatch.DrawString(Bold, "Tractor Speed:" + tractorUnit.getTractorSpeed().ToString(), new Vector2(100, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White);
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 60), Color.White);spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 40), Color.White);
spriteBatch.DrawString(Bold, "Tractor Rotation:" + tractorUnit.getRotation().ToString() + " Degrees", new Vector2(250, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 20), Color.White);
spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 80), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, tractorUnit.getScore().ToString(), new Vector2(10, input.getSize().Y * (input.getTileSize() + input.getSpacing()) + 100), Color.White);
spriteBatch.Draw(tractor, new Rectangle((int)mousePosition.X, (int)mousePosition.Y, input.getTileSize() / 4, input.getTileSize() / 4), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}

View File

@ -44,14 +44,20 @@
<Compile Include="Game1.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Sources\House.cs" />
<Compile Include="Sources\Crops.cs" />
<Compile Include="Sources\Farm.cs" />
<Compile Include="Sources\Input.cs" />
<Compile Include="Sources\Queue.cs" />
<Compile Include="Sources\SmartTractor.cs" />
<Compile Include="Sources\Task.cs" />
<Compile Include="Sources\Tractor.cs" />
<Compile Include="Sources\Objects\House.cs" />
<Compile Include="Sources\Crops\Crops.cs" />
<Compile Include="Sources\Crops\Farm.cs" />
<Compile Include="Sources\Controlls\Input.cs" />
<Compile Include="Sources\Objects\tractorPositionCorrector.cs" />
<Compile Include="Sources\Pathing\A-Star\Astar.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\MinHeap.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\Nodes.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\Path.cs" />
<Compile Include="Sources\Pathing\A-Star\PathSaver\PriorityQueue.cs" />
<Compile Include="Sources\Controlls\Controller.cs" />
<Compile Include="Sources\Smart\ScoreSystem.cs" />
<Compile Include="Sources\Smart\SmartTractor.cs" />
<Compile Include="Sources\Objects\Tractor.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="MonoGame.Framework">
@ -63,7 +69,8 @@
<ItemGroup>
<Content Include="Content\Crop.png" />
<Content Include="Content\house.png" />
<Content Include="Content\Plantable.png" />
<Content Include="Content\Markers.png" />
<Content Include="Content\Mountain.png" />
<Content Include="Content\Planted.png" />
<Content Include="Content\Tile.png" />
<Content Include="Content\tileunplantable.png" />

View File

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

@ -0,0 +1,100 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
using System;
class Controller
{
private KeyboardState state = Keyboard.GetState();
private GraphicsDeviceManager graphics;
private bool heldUp = false;
public void init(GraphicsDeviceManager Graphics)
{
graphics = Graphics;
}
public Vector2 updateWindow(int tileSize, int Spacing, Vector2 Size)
{
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.D) && Size.X < 100)
{
Size.X++;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
}
if (state.IsKeyDown(Keys.A) && Size.X > 2)
{
Size.X--;
graphics.PreferredBackBufferWidth = (tileSize + Spacing) * (int)Size.X - Spacing;
}
if (state.IsKeyDown(Keys.W) && Size.Y < 20)
{
Size.Y++;
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
}
if (state.IsKeyDown(Keys.S) && Size.Y > 2)
{
Size.Y--;
graphics.PreferredBackBufferHeight = (tileSize + Spacing) * (int)Size.Y - Spacing + 100;
}
return Size;
}
public int controllTileSize(Vector2 Size, int tileSize)
{
if (Size.X * tileSize + 5 > GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width)
{
tileSize--;
}
if (Size.X * tileSize - 5 < GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width && tileSize < 56)
{
tileSize++;
}
return tileSize;
}
public int controllSpeed(int Speed)
{
KeyboardState state = Keyboard.GetState();
if (state.IsKeyDown(Keys.Right))
{
Speed++;
}
if (state.IsKeyDown(Keys.Left) && Speed > 0)
{
Speed--;
}
return Speed;
}
public tractorPositionCorrector controllTractorSpeed(float tractorSpeed, Vector2 Position)
{
KeyboardState state = Keyboard.GetState();
tractorPositionCorrector Corrector = new tractorPositionCorrector(Position, tractorSpeed);
if (!heldUp)
{
if (state.IsKeyDown(Keys.Up) && tractorSpeed < 1)
{
Corrector.setTractorSpeed(tractorSpeed * 2);
heldUp = true;
}
else if (state.IsKeyDown(Keys.Down) && tractorSpeed > 0.0009765625)
{
Corrector.setTractorSpeed(tractorSpeed / 2);
heldUp = true;
}
}
else if (heldUp && !(state.IsKeyDown(Keys.Down) || state.IsKeyDown(Keys.Up)))
{
heldUp = false;
Corrector.setPosition((float)Math.Ceiling(Position.X), (float)Math.Ceiling(Position.Y));
}
return Corrector;
}
}

View File

@ -0,0 +1,72 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class Input
{
private KeyboardState state = Keyboard.GetState();
private GraphicsDeviceManager graphics;
private Vector2 Size;
private int tileSize;
private int Spacing;
private Controller controller = new Controller();
public void init(GraphicsDeviceManager Graphics, Vector2 size, int TileSize, int SPacing)
{
graphics = Graphics;
tileSize = TileSize;
Spacing = SPacing;
Size = size;
controller.init(Graphics);
}
public int changeSpeed(int Speed)
{
return controller.controllSpeed(Speed);
}
public tractorPositionCorrector changeTractorSpeed(float tractorSpeed, Vector2 Position)
{
return controller.controllTractorSpeed(tractorSpeed, Position);
}
private void changeSize()
{
Size = controller.updateWindow(tileSize, Spacing, Size);
}
public void controlWindowSize()
{
tileSize = controller.controllTileSize(Size, tileSize);
changeSize();
graphics.ApplyChanges();
}
public int getTileSize()
{
return tileSize;
}
public int getSpacing()
{
return Spacing;
}
public Vector2 getSize()
{
return Size;
}
public int getSpacingTile()
{
return Spacing + tileSize;
}
public void setTileSize(int newTileSize)
{
tileSize = newTileSize;
}
}

View File

@ -0,0 +1,63 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class Crops
{
public int x;
public int y;
public int Status;
private int cropType;
private int Timer;
private Random r;
public void updateCrop()
{
if (Status != 0)
{
Timer--;
}
}
public int getCropTimer()
{
return Timer;
}
public int getCostOnMovement()
{
if (Status == 1) //grass
{
return 1;
}
else if (Status == 2) //dirt
{
return 8;
}
else if (Status == 3) //crops
{
return 15;
}
else
{
return 30;
}
}
public void setPosition(int newx, int newy)
{
x = newx;
y = newy;
}
public void setCropType(int Type)
{
}
}

View File

@ -0,0 +1,96 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
class Farm
{
private Crops[,] crops;
private Random r;
//initializes the crops
public void init(Vector2 Size)
{
r = new Random();
crops = new Crops[100, 100];
for (int i = 0; i < Size.X; i++)
{
for (int j = 0; j < Size.Y; j++)
{
int x = r.Next(0, 3);
if (x == 0)
{
x = r.Next(0, 2);
}
if (x == 2)
{
x = r.Next(1, 3);
}
crops[i, j] = new Crops();
crops[i, j].Status = x;
}
}
}
public void updateFarm(Vector2 Size)
{
for (int i = 0; i > Size.X; i++)
{
for (int j = 0; j > Size.Y; j++)
{
crops[i, j].updateCrop();
}
}
}
//Changes the properties of the tile when the tractor reaches this tile.
public void setCropStatus(float xfloat, float yfloat, int Spacing)
{
int x = (int)xfloat / Spacing;
int y = (int)yfloat / Spacing;
if (crops[x, y].Status == 4)
{
crops[x, y].Status = 2;
}
else if(crops[x, y].Status == 0)
{
//do nothing
}
else if (crops[x, y].Status == 2)
{
crops[x, y].Status = 3;
}
else if (crops[x, y].Status == 3)
{
crops[x, y].Status = 4;
}
}
public Crops getCrop(int x, int y)
{
return crops[x,y];
}
public Crops[,] getCrops()
{
return crops;
}
public void updateSize(Vector2 Size, int tileSize, int Spacing)
{
for (int i = 0; i < (int)Size.X; i++)
{
for (int j = 0; j < (int)Size.Y; j++)
{
crops[i, j].x = (tileSize + Spacing) * i;
crops[i, j].y = (tileSize + Spacing) * j;
}
}
}
}

View File

@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
class House
{
private Rectangle housePos;
private Vector2 pos;
private Random r = new Random();
//initializes the house
public void init(int tileSize, int Spacing)
{
int x = r.Next(0, 8);
int y = r.Next(0, 8);
pos = new Vector2(x, y);
housePos = new Rectangle((x * tileSize + Spacing), y * (tileSize + Spacing), tileSize, tileSize);
}
//Moves the house if it is currently out of matrix.
public void updateRectangle(Vector2 Size, int tileSize, int Spacing)
{
if (pos.X + 1 > Size.X)
{
pos = new Vector2(pos.X - 1, pos.Y);
}
if (pos.Y + 1 > Size.Y)
{
pos = new Vector2(pos.X, pos.Y - 1);
}
housePos = new Rectangle((int)pos.X * (tileSize + Spacing), (int)pos.Y * (tileSize + Spacing), tileSize, tileSize);
}
public Rectangle GetRectangle()
{
return housePos;
}
public Vector2 getVector()
{
return new Vector2(housePos.X, housePos.Y);
}
}

View File

@ -0,0 +1,309 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
class Tractor
{
private int Spacing, sizeTile, Speed = 1, Rotation = 180, rotationSpeed = 5;
private float tractorSpeed = 1;
private String currentTask;
private Vector2 Position, TargetPosition, Direction, Size, housePos;
private Path path = new Path();
private Random r = new Random();
private Farm farm = new Farm();
private SmartTractor smartTractor = new SmartTractor();
private ScoreSystem scoreSystem = new ScoreSystem();
public void updateSizing(Input input, int Status, Vector2 newHousePos)
{
Spacing = input.getSpacing();
sizeTile = input.getTileSize();
Size = input.getSize();
updatePosition(input.getSize(), Status);
housePos = newHousePos;
}
public void init(Rectangle house, Input input)
{
sizeTile = input.getTileSize();
Spacing = input.getSpacing();
farm.init(new Vector2(100, (GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height / sizeTile) - 125 / sizeTile));
Position = housePos;
TargetPosition = new Vector2(house.X, house.Y);
}
// Runs when the tractor reaches a tile
private void updateDirection(Vector2 Size, Vector2 newPosition)
{
Vector2 DeltaPosition = TargetPosition - Position;
if (DeltaPosition.X == 0)
{
if (DeltaPosition.Y == 0)
{
calculateNewPath(newPosition);
}
else if (DeltaPosition.Y > 0)
{
updateRotation(0);
}
else if (DeltaPosition.Y < 0)
{
updateRotation(1);
}
}
else if (DeltaPosition.X > 0)
{
updateRotation(2);
}
else if (DeltaPosition.X < 0)
{
updateRotation(3);
}
}
//Moves the tractor
public void updatePosition(Vector2 Size, int Status) /// updates the position
{
farm.updateSize(Size, sizeTile, Spacing);
for (int i = 0; i < Speed; i++) //Where all the choices the tractor does comes from
{
smartTractor.updateMap(Position, housePos, farm.getCrops(), Size, sizeTile, Spacing, scoreSystem.getScore(), Rotation);
updateDirection(Size, Position);
}
}
public void calculateNewPath(Vector2 newPosition)
{
if (path.getCount() == 0)
{
if (housePos != Position)
{
//Returns to the farm
int x = (int)Position.X / (sizeTile + Spacing);
int y = (int)Position.Y / (sizeTile + Spacing);
currentTask = scoreSystem.MessageAndScore(farm.getCrop(x, y).Status, 0);
farm.setCropStatus(x, y, Spacing);
path = smartTractor.returnChoice(0);
}
else
{
//Sets a random Target
int xTarget = (int)TargetPosition.X / (sizeTile + Spacing);
int yTarget = (int)TargetPosition.Y / (sizeTile + Spacing);
currentTask = scoreSystem.MessageAndScore(farm.getCrop(xTarget, yTarget).Status, 1);
path = smartTractor.returnChoice(1);
}
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
updateDirection(Size, newPosition);
}
else
{
TargetPosition = path.Reduce().getCords() * (sizeTile + Spacing);
updateDirection(Size, newPosition);
}
}
private void updateRotation(int Destination)
{
if (Destination == 0)
{
if (Rotation == 0)
{
Direction = new Vector2(0, 1) * tractorSpeed;
Position = Position + Direction;
}
else
{
if (Rotation == 0)
{
//Do nothing
}
else if (Rotation > 180)
{
if (Rotation >= 360)
{
Rotation = 0;
}
Rotation = Rotation + rotationSpeed;
}
else if (Rotation <= 180 && Rotation > 0)
{
Rotation = Rotation - rotationSpeed;
}
}
}
else if (Destination == 1)
{
if (Rotation == 180)
{
Direction = new Vector2(0, -1) * tractorSpeed;
Position = Position + Direction;
}
else
{
if (Rotation == 180)
{
//Do nothing
}
else if (Rotation >= 0 && Rotation < 180)
{
Rotation = Rotation + rotationSpeed;
}
else if (Rotation < 360 && Rotation > 180)
{
Rotation = Rotation - rotationSpeed;
}
}
}
else if (Destination == 2)
{
if (Rotation == 270)
{
Direction = new Vector2(1, 0) * tractorSpeed;
Position = Position + Direction;
}
else
{
if (Rotation == 270)
{
//Do nothing
}
else if (Rotation > 90 && Rotation < 270)
{
Rotation = Rotation + rotationSpeed;
}
else if (Rotation < 90 || Rotation < 360)
{
if (Rotation <= 0)
{
Rotation = 360;
}
Rotation = Rotation - rotationSpeed;
}
}
}
else if (Destination == 3)
{
if (Rotation == 90)
{
Direction = new Vector2(-1, 0) * tractorSpeed;
Position = Position + Direction;
}
else
{
if (Rotation == 90)
{
//Do nothing
}
else if ( Rotation < 270 && Rotation > 90)
{
Rotation = Rotation - rotationSpeed;
}
else if (Rotation >= 0 || Rotation > 270)
{
if (Rotation >= 360)
{
Rotation = 0;
}
Rotation = Rotation + rotationSpeed;
}
}
}
}
public float getRotation()
{
return MathHelper.ToRadians(Rotation);
}
public Vector2 getPos()
{
return Position;
}
public void increaseSpeed()
{
Speed++;
}
public void decreaseSpeed()
{
if (Speed > 0)
{
Speed--;
}
}
public void setSpeed(int newSpeed)
{
Speed = newSpeed;
}
public void setTractorSpeed(tractorPositionCorrector corrector)
{
tractorSpeed = corrector.getTractorSpeed();
Position = corrector.getPosition();
}
public int getSpeed()
{
return Speed;
}
public float getTractorSpeed()
{
return tractorSpeed;
}
public void setPos(Vector2 newPos)
{
Position = newPos;
}
public Farm getFarm()
{
return farm;
}
public Vector2 getTargetPosition()
{
return TargetPosition;
}
public String getCurrentTask()
{
return currentTask;
}
public int getScore()
{
return scoreSystem.getScore();
}
public Path getPath()
{
return path;
}
}

View File

@ -0,0 +1,36 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
class tractorPositionCorrector
{
Vector2 mPosition;
float mTractorSpeed;
public tractorPositionCorrector(Vector2 position, float TractorSpeed)
{
mPosition = position;
mTractorSpeed = TractorSpeed;
}
public Vector2 getPosition()
{
return mPosition;
}
public float getTractorSpeed()
{
return mTractorSpeed;
}
public void setPosition(float x, float y)
{
mPosition = new Vector2(x,y);
}
public void setTractorSpeed(float newSpeed)
{
mTractorSpeed = newSpeed;
}
}

View File

@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
class Astar
{
private Vector2 tractorPos;
private Vector2 housePos;
private Crops[,] crops;
private Vector2 Size;
private PriorityQueue allPaths;
private Vector2 targetPos;
private int Rotation;
public void update(Crops[,] newCrops, Vector2 newSize, Vector2 newTractorPos, Vector2 newHousePos, Vector2 newtargetPos, int rotation)
{
tractorPos = new Vector2((int)newTractorPos.X, (int)newTractorPos.Y);
housePos = new Vector2((int)newHousePos.X, (int)newHousePos.Y);
targetPos = newtargetPos;
crops = newCrops;
Size = newSize;
Rotation = rotation;
}
public Nodes getOptimalPath()
{
return allPaths.Peek();
}
// Get all adjacent nodes
private List<Nodes> GetAdjacentNodes(Vector2 currentPos)
{
var adjacentNodes = new List<Nodes>()
{
new Nodes(new Vector2(currentPos.X, currentPos.Y+1), 0),
new Nodes(new Vector2(currentPos.X + 1, currentPos.Y), 1),
new Nodes(new Vector2(currentPos.X, currentPos.Y - 1), 2),
new Nodes(new Vector2(currentPos.X - 1, currentPos.Y), -1),
};
//check if out of range
for (int i = 3; i >= 0; i--)
{
if (adjacentNodes[i].getCords().X < 0 || adjacentNodes[i].getCords().Y < 0)
adjacentNodes.Remove(adjacentNodes[i]);
else
{
if (adjacentNodes[i].getCords().X > Size.X - 1 || adjacentNodes[i].getCords().Y > Size.Y - 1)
adjacentNodes.Remove(adjacentNodes[i]);
}
}
// return if not an obstacle
return adjacentNodes.Where(
item => crops[(int)item.getCords().X, (int)item.getCords().Y].Status != 0).ToList();
}
// Heuristic function, Manhattan method.
public int ComputeHScore(Vector2 currentNode, Vector2 endNote)
{
return (int)(Math.Abs(endNote.X - currentNode.X) + Math.Abs(endNote.Y - currentNode.Y));
}
// Rotation Cost
public int CalculateRotationCost(int currDir, int newDir)
{
if (currDir == newDir)
return 0;
else if (Math.Abs(currDir - newDir) == 1 || Math.Abs(currDir - newDir) == 3)
return 2;
else if (Math.Abs(currDir - newDir) == 0 || Math.Abs(currDir - newDir) == 2)
return 9;
return 0;
}
// Convert rotation used by sprite, to get direction of first node in next path
public int ConvertRotation()
{
int rotation = 0;
if (Rotation == 180)
rotation = 0;
else if (Rotation == 270)
rotation = 1;
else if (Rotation == 0)
rotation = 2;
else if (Rotation == 90)
rotation = -1;
return rotation;
}
// Main function of A* algorithm
public Path FindPath()
{
int g = 0;
int direction = ConvertRotation();
Path path = new Path();
MinHeap openList = new MinHeap();
MinHeap closedList = new MinHeap();
Nodes target = new Nodes(targetPos);
Nodes startPos = new Nodes(tractorPos, direction);
Nodes current = null;
openList.Insert(startPos);
while (openList.GetSize() > 0)
{
current = openList.getMin();
closedList.Insert(current);
openList.removeMin();
direction = current.getDirection();
if (current.getCords() == target.getCords())
break;
var adjacentNodes = GetAdjacentNodes(current.getCords());
foreach (var adjacentNode in adjacentNodes)
{
if (closedList.Exists(adjacentNode.getCords())) // check if adjacent node is on closed list, if it is, skip it
continue;
g = current.getG() + crops[(int)adjacentNode.getCords().X, (int)adjacentNode.getCords().Y].getCostOnMovement() + CalculateRotationCost(direction, adjacentNode.getDirection()); // calculate g - cost from start point
if (!(openList.Exists(adjacentNode.getCords()))) // if adjacent node is not on open list, add it
{
adjacentNode.setG(g);
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
adjacentNode.calculateF();
adjacentNode.setParent(current);
openList.Insert(adjacentNode);
}
else
{
if (g + adjacentNode.getH() < adjacentNode.getF()) // check if adjacent node is a better path than the current one
{
adjacentNode.setG(g);
adjacentNode.calculateF();
adjacentNode.setParent(current);
}
}
}
}
// backtrack to create path
while (current != null)
{
path.AddNode(current);
current = current.getParent();
}
path = path.FlipArray();
openList.deleteHeap();
closedList.deleteHeap();
return path;
}
}

View File

@ -0,0 +1,193 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class MinHeap
{
List<Nodes> arr = new List<Nodes>();
public MinHeap()
{
arr = new List<Nodes>();
}
public void Insert(Nodes value)
{
arr.Add(value);
siftUp(arr.Count - 1);
}
public void removeMin()
{
if (arr.Count == 0)
{
throw new Exception("Heap is empty!");
}
else
{
arr[0] = arr[arr.Count - 1];
arr.RemoveAt(arr.Count - 1);
if (arr.Count > 0)
{
siftDown(0);
}
}
}
private void siftUp(int index)
{
int parentIndex;
Nodes temp;
if (index != 0)
{
parentIndex = getParentIndex(index);
if (arr[parentIndex].getF() > arr[index].getF())
{
temp = arr[parentIndex];
arr[parentIndex] = arr[index];
arr[index] = temp;
siftUp(parentIndex);
}
}
}
private int getParentIndex(int index)
{
return (index - 1) / 2;
}
private void siftDown(int nodeIndex)
{
int leftChildIndex, rightChildIndex, minIndex;
Nodes tmp;
leftChildIndex = getLeftChildIndex(nodeIndex);
rightChildIndex = getRightChildIndex(nodeIndex);
if (rightChildIndex >= arr.Count)
{
if (leftChildIndex >= arr.Count)
{
return;
}
else
{
minIndex = leftChildIndex;
}
}
else
{
if (arr[leftChildIndex].getF() <= arr[rightChildIndex].getF())
{
minIndex = leftChildIndex;
}
else
{
minIndex = rightChildIndex;
}
}
if (arr[nodeIndex].getF() > arr[minIndex].getF())
{
tmp = arr[minIndex];
arr[minIndex] = arr[nodeIndex];
arr[nodeIndex] = tmp;
siftDown(minIndex);
}
}
private int getRightChildIndex(int nodeIndex)
{
return (2 * nodeIndex) + 2;
}
private int getLeftChildIndex(int nodeIndex)
{
return (2 * nodeIndex) + 1;
}
public Nodes getMin()
{
return arr[0];
}
public void BuildMinHeap(List<Nodes> input)
{
if (arr.Count > 0)
{
//clear the current heap
for (int i = 0; i < arr.Count; i++)
{
arr[i] = input[i];
}
}
for (int i = arr.Count - 1 / 2; i >= 0; i--)
{
MinHeapify(i);
}
}
private void MinHeapify(int index)
{
int left = 2 * index;
int right = (2 * index) + 1;
int smallest = index;
if (left < arr.Count && arr[left].getF() < arr[index].getF())
{
smallest = left;
}
else
{
smallest = index;
}
if (right < arr.Count && arr[right].getF() < arr[smallest].getF())
{
smallest = right;
}
if (smallest != index)
{
swap(ref arr, index, smallest);
MinHeapify(smallest);
}
}
private void swap(ref List<Nodes> input, int a, int b)
{
Nodes temp = input[a];
input[a] = input[b];
input[b] = temp;
}
public int GetSize()
{
return arr.Count;
}
public Boolean Exists(Vector2 coordinates)
{
if (arr.Count == 0)
return false;
foreach (Nodes node in arr)
{
if (node.getCords() == coordinates)
return true;
}
return false;
}
public List<Nodes> GetList()
{
return arr;
}
public void deleteHeap()
{
arr.Clear();
}
}

View File

@ -0,0 +1,97 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class Nodes
{
private int F = 0;
private int G = 0;
private int H = 0;
private Vector2 Coordinates;
private Nodes Parent = null;
private int Direction = 0;
public Nodes(Vector2 coordinates)
{
Coordinates = coordinates;
}
public Nodes(Vector2 coordinates, int direction)
{
Coordinates = coordinates;
Direction = direction;
}
public Nodes(Nodes node)
{
F = node.F;
G = node.G;
H = node.H;
Coordinates = node.Coordinates;
Parent = node.Parent;
}
public Nodes(int f, int g, int h, Vector2 coordinates, Nodes parent)
{
F = f;
G = g;
H = h;
Coordinates = coordinates;
Parent = parent;
}
public Vector2 getCords()
{
return Coordinates;
}
public int getF()
{
return F;
}
public int getG()
{
return G;
}
public int getH()
{
return H;
}
public void calculateF()
{
F = G + H;
}
public void setG(int g)
{
G = g;
}
public void setH(int h)
{
H = h;
}
public Nodes getParent()
{
return Parent;
}
public void setParent(Nodes parent)
{
Parent = parent;
}
public int getDirection()
{
return Direction;
}
}

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class Path
{
private Nodes[] nodes = new Nodes[512];
private int Count = 0;
public void AddNode(Nodes node)
{
nodes[Count] = new Nodes(node);
Count++;
}
public Nodes Reduce()
{
Count--;
Nodes temp = nodes[0];
for (int i = 0; i < Count; i++)
{
nodes[i] = nodes[i + 1];
}
nodes[Count + 1] = null;
return temp;
}
public Path FlipArray()
{
int j = Count;
Nodes[] tempp = nodes;
Nodes[] newnode = new Nodes[Count];
Path newPath = new Path();
for (int i = 0; i < Count; i++)
{
newnode[i] = tempp[j - 1];
j--;
newPath.AddNode(newnode[i]);
}
return newPath;
}
public Nodes getFinalDest()
{
return nodes[Count];
}
public int getCount()
{
return Count;
}
public Nodes getByIndex(int i)
{
return nodes[i];
}
}

View File

@ -0,0 +1,88 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;
class PriorityQueue
{
public List<Nodes> list;
public int Count { get { return list.Count; } }
public PriorityQueue()
{
list = new List<Nodes>();
}
public PriorityQueue(int count)
{
list = new List<Nodes>(count);
}
public void Enqueue(Nodes x)
{
list.Add(x);
int i = Count - 1;
while (i > 0)
{
int p = (i - 1) / 2;
if (list[p].getF() <= x.getF()) break;
list[i] = list[p];
i = p;
}
if (Count > 0) list[i] = x;
}
public void Dequeue()
{
Nodes min = Peek();
Nodes root = list[Count - 1];
list.RemoveAt(Count - 1);
int i = 0;
while (i * 2 + 1 < Count)
{
int a = i * 2 + 1;
int b = i * 2 + 2;
int c = b < Count && list[b].getF() < list[a].getF() ? b : a;
if (list[c].getF() >= root.getF()) break;
list[i] = list[c];
i = c;
}
if (Count > 0) list[i] = root;
}
public Nodes Peek()
{
if (Count == 0) throw new InvalidOperationException("Queue is empty.");
return list[0];
}
public Boolean Exists(Vector2 coordinates)
{
if (Count == 0)
return false;
foreach(Nodes node in list)
{
if (node.getCords() == coordinates)
return true;
}
return false;
}
public void Clear()
{
list.Clear();
}
}

View File

@ -0,0 +1,75 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class ScoreSystem
{
private int Score = 0;
private int previousTask;
//Message which is displaying what the tractor is currently doing.
public String MessageAndScore(int Status, int Stage)
{
previousTask = Status;
if (previousTask == 3 && Stage != 1)
{
Score++;
}
//When the Tractor is going back to the farm.
if (Stage == 0)
{
if (Status == 1)
{
return "Returning with nothing after going out for a stroll";
}
else if (Status == 2)
{
return "Returning with nothing after planting seeds";
}
else if (Status == 3)
{
return "Returning with nothing after adding fertilizer";
}
else if (Status == 4)
{
return "Returning with Crops";
}
else
{
return "Error";
}
}
//When the Tractor is going back to work.
else
{
if (Status == 1)
{
return "Going for a stroll";
}
else if (Status == 2)
{
return "Planting seeds";
}
else if (Status == 3)
{
return "Adding fertilizer";
}
else if (Status == 4)
{
return "Going for Crops";
}
else
{
return "Error";
}
}
}
public int getScore()
{
return Score;
}
}

View File

@ -0,0 +1,120 @@
using System;
using Microsoft.Xna.Framework;
using System;
class SmartTractor
{
private Crops[,] crops;
private Vector2 housePos;
private Vector2 tractorPos;
private Vector2 Size;
private Vector2 Target;
private Path path;
private int tileSize;
private int Score;
private int Spacing;
private Random r = new Random();
private Astar astar = new Astar();
private int Rotation;
//What to do next
public Path returnChoice(int task)
{
if (task == 0)
{
//To the house
getTargetPosition((int)housePos.X / (tileSize + Spacing), (int)housePos.Y / (tileSize + Spacing));
}
else
{
//To the fields
getTargetPosition(r.Next(0, (int)Size.X), r.Next(0, (int)Size.Y));
}
astar.update(crops, Size, tractorPos / (tileSize + Spacing), housePos / (tileSize + Spacing), Target/(tileSize+Spacing), Rotation);
//astar.FindPath();
return astar.FindPath();
}
//Updates the variables every frame
public void updateMap(Vector2 newTractorPos, Vector2 newHousePos, Crops[,] newCropsStatus, Vector2 newSize, int newTileSize, int newSpacing, int newScore, int rotation)
{
crops = newCropsStatus;
housePos = newHousePos;
tractorPos = newTractorPos;
Size = newSize;
tileSize = newTileSize;
Spacing = newSpacing;
Score = newScore;
Rotation = rotation;
}
private void getTargetPosition(int x, int y)
{
Target = new Vector2(x, y) * (tileSize + Spacing);
}
/*
//Only for testing without obstacles
private void createPath()
{
path = new Path();
Vector2 targetPos = Target / (tileSize + Spacing);
Vector2 currentPath = tractorPos / tileSize;
currentPath.X = (float)Math.Round(currentPath.X);
currentPath.Y = (float)Math.Round(currentPath.Y);
do
{
if (currentPath.X == targetPos.X)
{
//found X pos
if (currentPath.Y == targetPos.Y)
{
//found y pos
}
else if (currentPath.Y < targetPos.Y)
{
currentPath = new Vector2(currentPath.X, currentPath.Y + 1);
path.setNode(currentPath, crops);
}
else if (currentPath.Y > targetPos.Y)
{
currentPath = new Vector2(currentPath.X, currentPath.Y - 1);
path.setNode(currentPath, crops);
}
}
else if (currentPath.X < targetPos.X)
{
currentPath = new Vector2(currentPath.X + 1, currentPath.Y);
path.setNode(currentPath, crops);
}
else if (currentPath.X > targetPos.X)
{
currentPath = new Vector2(currentPath.X - 1, currentPath.Y);
path.setNode(currentPath, crops);
}
} while (currentPath != targetPos);
}
public void setNode(Vector2 newNode, Crops[,] Crop)
{
nodes[Count] = new Nodes(Crop[(int)newNode.X, (int)newNode.Y].getCostOnMovement(), newNode);
Count++;
}
*/
}

261
Tractor_VS/.gitignore vendored
View File

@ -1,261 +0,0 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs
# Build results
[Dd]ebug/
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
bld/
[Bb]in/
[Oo]bj/
[Ll]og/
# Visual Studio 2015 cache/options directory
.vs/
# Uncomment if you have tasks that create the project's static files in wwwroot
#wwwroot/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
# NUNIT
*.VisualState.xml
TestResult.xml
# Build Results of an ATL Project
[Dd]ebugPS/
[Rr]eleasePS/
dlldata.c
# DNX
project.lock.json
project.fragment.lock.json
artifacts/
*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.svclog
*.scc
# Chutzpah Test files
_Chutzpah*
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opendb
*.opensdf
*.sdf
*.cachefile
*.VC.db
*.VC.VC.opendb
# Visual Studio profiler
*.psess
*.vsp
*.vspx
*.sap
# TFS 2012 Local Workspace
$tf/
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
*.DotSettings.user
# JustCode is a .NET coding add-in
.JustCode
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
_NCrunch_*
.*crunch*.local.xml
nCrunchTemp_*
# MightyMoose
*.mm.*
AutoTest.Net/
# Web workbench (sass)
.sass-cache/
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.[Pp]ublish.xml
*.azurePubxml
# TODO: Comment the next line if you want to checkin your web deploy settings
# but database connection strings (with potential passwords) will be unencrypted
#*.pubxml
*.publishproj
# Microsoft Azure Web App publish settings. Comment the next line if you want to
# checkin your Azure Web App publish settings, but sensitive information contained
# in these scripts will be unencrypted
PublishScripts/
# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config
# NuGet v3's project.json files produces more ignoreable files
*.nuget.props
*.nuget.targets
# Microsoft Azure Build Output
csx/
*.build.csdef
# Microsoft Azure Emulator
ecf/
rcf/
# Windows Store app package directories and files
AppPackages/
BundleArtifacts/
Package.StoreAssociation.xml
_pkginfo.txt
# Visual Studio cache files
# files ending in .cache can be ignored
*.[Cc]ache
# but keep track of directories ending in .cache
!*.[Cc]ache/
# Others
ClientBin/
~$*
*~
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
# Since there are multiple workflows, uncomment next line to ignore bower_components
# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
#bower_components/
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file
# to a newer Visual Studio version. Backup files are not needed,
# because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
*.mdf
*.ldf
# Business Intelligence projects
*.rdl.data
*.bim.layout
*.bim_*.settings
# Microsoft Fakes
FakesAssemblies/
# GhostDoc plugin setting file
*.GhostDoc.xml
# Node.js Tools for Visual Studio
.ntvs_analysis.dat
# Visual Studio 6 build log
*.plg
# Visual Studio 6 workspace options file
*.opt
# Visual Studio LightSwitch build output
**/*.HTMLClient/GeneratedArtifacts
**/*.DesktopClient/GeneratedArtifacts
**/*.DesktopClient/ModelManifest.xml
**/*.Server/GeneratedArtifacts
**/*.Server/ModelManifest.xml
_Pvt_Extensions
# Paket dependency manager
.paket/paket.exe
paket-files/
# FAKE - F# Make
.fake/
# JetBrains Rider
.idea/
*.sln.iml
# CodeRush
.cr/
# Python Tools for Visual Studio (PTVS)
__pycache__/
*.pyc

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 573 B

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<SourceFileCollection xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Profile>Reach</Profile>
<Platform>Windows</Platform>
<Config />
<SourceFiles>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Crop.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Font.spritefont</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/house.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Plantable.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Planted.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tile.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/tileunplantable.png</File>
<File>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tractor.png</File>
</SourceFiles>
<DestFiles>
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
<File xsi:nil="true" />
</DestFiles>
</SourceFileCollection>

View File

@ -1,9 +0,0 @@
Source File,Dest File,Processor Type,Content Type,Source File Size,Dest File Size,Build Seconds
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Crop.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Crop.xnb","TextureProcessor","Texture2DContent",3681,262229,0.2164986
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Font.spritefont","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Font.xnb","FontDescriptionProcessor","SpriteFontContent",2008,21524,0.1952166
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/house.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/house.xnb","TextureProcessor","Texture2DContent",1226,40085,0.003001
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Plantable.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Plantable.xnb","TextureProcessor","Texture2DContent",776,262229,0.0060014
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Planted.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Planted.xnb","TextureProcessor","Texture2DContent",3958,262229,0.0060017
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tile.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Tile.xnb","TextureProcessor","Texture2DContent",828,262229,0.008001
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/tileunplantable.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/tileunplantable.xnb","TextureProcessor","Texture2DContent",1823,1000085,0.0220053
"C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tractor.png","C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Tractor.xnb","TextureProcessor","Texture2DContent",573,12853,0.0020008

View File

@ -1,22 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PipelineBuildEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SourceFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Font.spritefont</SourceFile>
<SourceTime>2018-12-08T17:35:46+01:00</SourceTime>
<DestFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Font.xnb</DestFile>
<DestTime>2020-04-08T20:07:48.1912196+02:00</DestTime>
<Importer>FontDescriptionImporter</Importer>
<ImporterTime>2020-02-26T06:46:56+01:00</ImporterTime>
<Processor>FontDescriptionProcessor</Processor>
<ProcessorTime>2020-02-26T06:46:56+01:00</ProcessorTime>
<Parameters>
<Key>PremultiplyAlpha</Key>
<Value>True</Value>
</Parameters>
<Parameters>
<Key>TextureFormat</Key>
<Value>Compressed</Value>
</Parameters>
<Dependencies />
<BuildAsset />
<BuildOutput />
</PipelineBuildEvent>

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PipelineBuildEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SourceFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tile.png</SourceFile>
<SourceTime>2020-04-08T20:07:05.8428994+02:00</SourceTime>
<DestFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Tile.xnb</DestFile>
<DestTime>2020-04-08T20:07:48.2152249+02:00</DestTime>
<Importer>TextureImporter</Importer>
<ImporterTime>2020-02-26T06:46:56+01:00</ImporterTime>
<Processor>TextureProcessor</Processor>
<ProcessorTime>2020-02-26T06:46:56+01:00</ProcessorTime>
<Parameters>
<Key>ColorKeyColor</Key>
<Value>255,0,255,255</Value>
</Parameters>
<Parameters>
<Key>ColorKeyEnabled</Key>
<Value>True</Value>
</Parameters>
<Parameters>
<Key>GenerateMipmaps</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>PremultiplyAlpha</Key>
<Value>True</Value>
</Parameters>
<Parameters>
<Key>ResizeToPowerOfTwo</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>MakeSquare</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>TextureFormat</Key>
<Value>Color</Value>
</Parameters>
<Dependencies />
<BuildAsset />
<BuildOutput />
</PipelineBuildEvent>

View File

@ -1,42 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<PipelineBuildEvent xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<SourceFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/Tractor.png</SourceFile>
<SourceTime>2020-04-06T14:11:32.7941423+02:00</SourceTime>
<DestFile>C:/Users/Oskar/Source/Repos/s425077/PotatoPlan/Tractor_VS/Game1/Content/bin/Windows/Content/Tractor.xnb</DestFile>
<DestTime>2020-04-08T20:07:48.2392297+02:00</DestTime>
<Importer>TextureImporter</Importer>
<ImporterTime>2020-02-26T06:46:56+01:00</ImporterTime>
<Processor>TextureProcessor</Processor>
<ProcessorTime>2020-02-26T06:46:56+01:00</ProcessorTime>
<Parameters>
<Key>ColorKeyColor</Key>
<Value>255,0,255,255</Value>
</Parameters>
<Parameters>
<Key>ColorKeyEnabled</Key>
<Value>True</Value>
</Parameters>
<Parameters>
<Key>GenerateMipmaps</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>PremultiplyAlpha</Key>
<Value>True</Value>
</Parameters>
<Parameters>
<Key>ResizeToPowerOfTwo</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>MakeSquare</Key>
<Value>False</Value>
</Parameters>
<Parameters>
<Key>TextureFormat</Key>
<Value>Color</Value>
</Parameters>
<Dependencies />
<BuildAsset />
<BuildOutput />
</PipelineBuildEvent>

View File

@ -1,117 +0,0 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
namespace Game1
{
/// <summary>
/// This is the main type for your game.
/// </summary>
public class Game1 : Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont Bold;
private Texture2D[] tile = new Texture2D[4];
private Texture2D tractor;
private Texture2D house;
private Tractor tractorUnit = new Tractor();
private Input input = new Input();
private House houseUnit = new House();
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
// TODO: Add your initialization logic here
base.Initialize();
//Generates the map with some random values
input.init(graphics, new Vector2(8,8), 56, 1); //Generates the starting size
houseUnit.init(input.getTileSize(), input.getSpacing()); //Generates the house position
tractorUnit.init(houseUnit.GetRectangle());
tractorUnit.updateSizing(input, 0, houseUnit.getVector());
tractorUnit.setPos(houseUnit.getVector());
graphics.PreferredBackBufferWidth = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().X;
graphics.PreferredBackBufferHeight = (input.getTileSize() + input.getSpacing()) * (int)input.getSize().Y + 125;
graphics.ApplyChanges();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
//Loads the PNG content and Fonts
tile[0] = Content.Load<Texture2D>("tileunplantable");
tile[1] = Content.Load<Texture2D>("Plantable");
tile[2] = Content.Load<Texture2D>("Planted");
tile[3] = Content.Load<Texture2D>("Crop");
tractor = Content.Load<Texture2D>("Tractor");
Bold = Content.Load<SpriteFont>("Font");
house = Content.Load<Texture2D>("house");
}
protected override void UnloadContent()
{
}
protected override void Update(GameTime gameTime) //updates every 60 seconds
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
Exit();
tractorUnit.updateSizing(input, 0, houseUnit.getVector()); //Updates the size
tractorUnit.setSpeed(input.changeSpeed(tractorUnit.getSpeed())); //Updates the speed of the tractor
input.controlWindowSize(); //Controls the size of the screen depending on the number of tiles
houseUnit.updateRectangle(input.getSize(), input.getTileSize());
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime) //Draw Function
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
for(int i = 0; i < input.getSize().X; i++) //Draw the tiles
{
for (int j = 0; j < input.getSize().Y; j++)
{
spriteBatch.Draw(tile[tractorUnit.getFarm().getCrop(i, j).Status], new Rectangle(i * (input.getTileSize() + input.getSpacing()), j * (input.getTileSize() + input.getSpacing()), input.getTileSize(), input.getTileSize()), Color.White);
}
}
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getTargetPosition().X, (int)tractorUnit.getTargetPosition().Y, input.getTileSize(), input.getTileSize()) , Color.Red); //Draws the current target of the tractor
spriteBatch.Draw(tractor, new Rectangle((int)tractorUnit.getPos().X, (int)tractorUnit.getPos().Y, input.getTileSize(), input.getTileSize()), Color.White);
spriteBatch.Draw(house, houseUnit.GetRectangle(), Color.White);
spriteBatch.DrawString(Bold, "Speed:" + tractorUnit.getSpeed().ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 20) , Color.White); //Draws the speed value
spriteBatch.DrawString(Bold, "Tile Size:" + input.getTileSize().ToString() + "pix", new Vector2(10, input.getSize().Y * input.getTileSize() + 40), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, "Matrix Size: " + input.getSize().X.ToString() + " X " + input.getSize().Y.ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 60), Color.White);
spriteBatch.DrawString(Bold, tractorUnit.getCurrentTask(), new Vector2(10, input.getSize().Y * input.getTileSize() + 80), Color.White); //Draws the tile size
spriteBatch.DrawString(Bold, tractorUnit.getScore().ToString(), new Vector2(10, input.getSize().Y * input.getTileSize() + 100), Color.White);
spriteBatch.End();
base.Draw(gameTime);
}
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1 +0,0 @@
cf25c9cac4cef71798408758988dea8332b39a3d

View File

@ -1,118 +0,0 @@
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Game1.exe
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Game1.pdb
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\MonoGame.Framework.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.XInput.dll
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\MonoGame.Framework.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.xml
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\SharpDX.XInput.xml
c:\users\joel\source\repos\Game1\Game1\obj\x86\Debug\Game1.csprojAssemblyReference.cache
c:\users\joel\source\repos\Game1\Game1\obj\x86\Debug\Game1.csproj.CoreCompileInputs.cache
c:\users\joel\source\repos\Game1\Game1\obj\x86\Debug\Game1.csproj.CopyComplete
c:\users\joel\source\repos\Game1\Game1\obj\x86\Debug\Game1.exe
c:\users\joel\source\repos\Game1\Game1\obj\x86\Debug\Game1.pdb
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Content\Tile.xnb
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Content\Tractor.xnb
c:\users\joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Content\Font.xnb
C:\Users\Joel\source\repos\Game1\Game1\bin\Windows\x86\Debug\Content\house.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Font.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\house.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tile.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\tileunplantable.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tractor.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.exe
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.pdb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.dll
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.xml
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csprojAssemblyReference.cache
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CoreCompileInputs.cache
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CopyComplete
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.exe
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.pdb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Plantable.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Planted.xnb
C:\Users\Joel\source\repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Crop.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Crop.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Font.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\house.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Plantable.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Planted.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tile.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\tileunplantable.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tractor.xnb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.exe
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.pdb
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.dll
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct2D1.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.xml
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csprojAssemblyReference.cache
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CoreCompileInputs.cache
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CopyComplete
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.exe
D:\Ny mapp (2)\Ny mapp (2)\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.pdb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Crop.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Font.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\house.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Plantable.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Planted.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tile.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\tileunplantable.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Content\Tractor.xnb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.exe
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\Game1.pdb
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.dll
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\MonoGame.Framework.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.DXGI.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.Direct3D11.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.MediaFoundation.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XAudio2.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\bin\Windows\x86\Debug\SharpDX.XInput.xml
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csprojAssemblyReference.cache
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CoreCompileInputs.cache
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.csproj.CopyComplete
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.exe
C:\Users\Oskar\Source\Repos\s425077\PotatoPlan\Tractor_VS\Game1\obj\x86\Debug\Game1.pdb

104
route-planning.md Normal file
View File

@ -0,0 +1,104 @@
# intelligent tractor route planning implementation report
A* has been implemented. As of now, there are 4 types of fields wtih different costs:
Grass - 1
Dirt - 7
Crops - 15
4th type are obstacles (mountains) which are unpassable.
Apart from costs of each fields also cost or turning the agent has been implemented.
Turning once costs 2
Turning twice costs 9
Cost of turning twice is so high to encourage the agent to try different path rather that just turning back after reaching its destination point.
All costs can be changed and are not final values.
Very rarely agent will make a little bump instead of going forward.
As of now we were not able to detect if it is a problem with A* algorithm or some other part of the program.
Snippets of code:
A* main loop:
while (openList.GetSize() > 0)
{
current = openList.getMin();
closedList.Insert(current);
openList.removeMin();
direction = current.getDirection();
if (current.getCords() == target.getCords())
break;
var adjacentNodes = GetAdjacentNodes(current.getCords());
foreach (var adjacentNode in adjacentNodes)
{
if (closedList.Exists(adjacentNode.getCords())) // check if adjacent node is on closed list, if it is, skip it
continue;
g = current.getG() + crops[(int)adjacentNode.getCords().X, (int)adjacentNode.getCords().Y].getCostOnMovement() + CalculateRotationCost(direction, adjacentNode.getDirection()); // calculate g - cost from start point
if (!(openList.Exists(adjacentNode.getCords()))) // if adjacent node is not on open list, add it
{
adjacentNode.setG(g);
adjacentNode.setH(ComputeHScore(adjacentNode.getCords(), target.getCords()));
adjacentNode.calculateF();
adjacentNode.setParent(current);
openList.Insert(adjacentNode);
}
else
{
if (g + adjacentNode.getH() < adjacentNode.getF()) // check if adjacent node is a better path than the current one
{
adjacentNode.setG(g);
adjacentNode.calculateF();
adjacentNode.setParent(current);
}
}
}
}
// backtrack to create path
while (current != null)
{
path.AddNode(current);
current = current.getParent();
}
Successor function:
private List<Nodes> GetAdjacentNodes(Vector2 currentPos)
{
var adjacentNodes = new List<Nodes>()
{
new Nodes(new Vector2(currentPos.X, currentPos.Y+1), 0),
new Nodes(new Vector2(currentPos.X + 1, currentPos.Y), 1),
new Nodes(new Vector2(currentPos.X, currentPos.Y - 1), 2),
new Nodes(new Vector2(currentPos.X - 1, currentPos.Y), -1),
};
//check if out of range
for (int i = 3; i >= 0; i--)
{
if (adjacentNodes[i].getCords().X < 0 || adjacentNodes[i].getCords().Y < 0)
adjacentNodes.Remove(adjacentNodes[i]);
else
{
if (adjacentNodes[i].getCords().X > Size.X - 1 || adjacentNodes[i].getCords().Y > Size.Y - 1)
adjacentNodes.Remove(adjacentNodes[i]);
}
}
// return if not an obstacle
return adjacentNodes.Where(
item => crops[(int)item.getCords().X, (int)item.getCords().Y].Status != 0).ToList();
}
Heuristic function:
public int ComputeHScore(Vector2 currentNode, Vector2 endNote)
{
return (int)(Math.Abs(endNote.X - currentNode.X) + Math.Abs(endNote.Y - currentNode.Y));
}