fix: add comments to "Recursion.LD_24"
This commit is contained in:
parent
633c91bb72
commit
8d86e85a6a
@ -5,10 +5,22 @@ using System.Web;
|
||||
|
||||
namespace LD_24.Code
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for keeping the result of path finding
|
||||
/// </summary>
|
||||
public class BestPizzeriaResult
|
||||
{
|
||||
/// <summary>
|
||||
/// Pizzeria to which every friend will go
|
||||
/// </summary>
|
||||
public Point Pizzeria { get; private set; }
|
||||
/// <summary>
|
||||
/// Meeting spot for friends
|
||||
/// </summary>
|
||||
public Point MeetingSpot { get; private set; }
|
||||
/// <summary>
|
||||
/// The turn number of steps that will be taken between all friends
|
||||
/// </summary>
|
||||
public int Cost { get; private set; }
|
||||
|
||||
public BestPizzeriaResult(Point pizzeria, Point meetingSpot, int cost)
|
||||
@ -17,5 +29,10 @@ namespace LD_24.Code
|
||||
MeetingSpot = meetingSpot;
|
||||
Cost = cost;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("BestPizzeriaResult{Pizzeria = {0}, MeetingSpot = {1}, Cost = {2}}", Pizzeria, MeetingSpot, Cost);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,8 +6,17 @@ using System.Web;
|
||||
|
||||
namespace LD_24.Code
|
||||
{
|
||||
public class InOutUtils
|
||||
/// <summary>
|
||||
/// Functions related to working with files
|
||||
/// </summary>
|
||||
public static class InOutUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Read a map from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Target file</param>
|
||||
/// <returns>A map loaded from the file</returns>
|
||||
/// <exception cref="Exception">If there was an invalid tile</exception>
|
||||
public static Map ReadMap(string filename)
|
||||
{
|
||||
string[] lines = File.ReadAllLines(filename);
|
||||
@ -42,6 +51,11 @@ namespace LD_24.Code
|
||||
return map;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a map to a file
|
||||
/// </summary>
|
||||
/// <param name="writer">Target file writer</param>
|
||||
/// <param name="map">Target map</param>
|
||||
public static void WriteMap(StreamWriter writer, Map map)
|
||||
{
|
||||
for (int y = 0; y < map.Height; y++)
|
||||
@ -74,6 +88,11 @@ namespace LD_24.Code
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out best pizzeria result to file
|
||||
/// </summary>
|
||||
/// <param name="writer">Target file</param>
|
||||
/// <param name="result">Target result</param>
|
||||
public static void WriteBestPizzeriaResult(StreamWriter writer, BestPizzeriaResult result)
|
||||
{
|
||||
if (result == null)
|
||||
@ -88,6 +107,11 @@ namespace LD_24.Code
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write out friend positions to file
|
||||
/// </summary>
|
||||
/// <param name="writer">Target file</param>
|
||||
/// <param name="friends">Target friends list</param>
|
||||
public static void WriteFriendPositions(StreamWriter writer, List<Point> friends)
|
||||
{
|
||||
foreach (var friend in friends)
|
||||
|
@ -1,16 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
|
||||
namespace LD_24.Code
|
||||
{
|
||||
/// <summary>
|
||||
/// Class used to store a single map
|
||||
/// </summary>
|
||||
public class Map
|
||||
{
|
||||
/// <summary>
|
||||
/// Tile map
|
||||
/// </summary>
|
||||
MapTile[,] data;
|
||||
/// <summary>
|
||||
/// Map width
|
||||
/// </summary>
|
||||
public int Width { get; set; }
|
||||
/// <summary>
|
||||
/// Map height
|
||||
/// </summary>
|
||||
public int Height { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Create an empty map
|
||||
/// </summary>
|
||||
/// <param name="width">Target width</param>
|
||||
/// <param name="height">Target height</param>
|
||||
public Map(int width, int height)
|
||||
{
|
||||
data = new MapTile[width, height];
|
||||
@ -18,21 +32,44 @@ namespace LD_24.Code
|
||||
Height = height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Change a single tile in map
|
||||
/// </summary>
|
||||
/// <param name="x">Target x</param>
|
||||
/// <param name="y">Target y</param>
|
||||
/// <param name="tile">Target tile</param>
|
||||
public void Set(int x, int y, MapTile tile)
|
||||
{
|
||||
data[x, y] = tile;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieve a single tile from map
|
||||
/// </summary>
|
||||
/// <param name="x">Target x</param>
|
||||
/// <param name="y">Target y</param>
|
||||
/// <returns>Tile at target position</returns>
|
||||
public MapTile Get(int x, int y)
|
||||
{
|
||||
return data[x, y];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a position is whithin the bounds of the map
|
||||
/// </summary>
|
||||
/// <param name="x"></param>
|
||||
/// <param name="y"></param>
|
||||
/// <returns></returns>
|
||||
public bool IsInBounds(int x, int y)
|
||||
{
|
||||
return x >= 0 && x < Width && y >= 0 && y < Height;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find all positions of a certain tile type
|
||||
/// </summary>
|
||||
/// <param name="tile"></param>
|
||||
/// <returns></returns>
|
||||
public List<Point> FindAll(MapTile tile)
|
||||
{
|
||||
List<Point> points = new List<Point>();
|
||||
@ -48,5 +85,10 @@ namespace LD_24.Code
|
||||
}
|
||||
return points;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return string.Format("Map{Width = {0}, Height = {1}}", Width, Height);
|
||||
}
|
||||
}
|
||||
}
|
@ -5,6 +5,9 @@ using System.Web;
|
||||
|
||||
namespace LD_24.Code
|
||||
{
|
||||
/// <summary>
|
||||
/// Enum for storing the type of each tile in a map
|
||||
/// </summary>
|
||||
public enum MapTile
|
||||
{
|
||||
Empty,
|
||||
|
@ -5,9 +5,18 @@ using System.Web;
|
||||
|
||||
namespace LD_24.Code
|
||||
{
|
||||
/// <summary>
|
||||
/// A simple point class for storing x and y together.
|
||||
/// </summary>
|
||||
public class Point
|
||||
{
|
||||
/// <summary>
|
||||
/// The x component
|
||||
/// </summary>
|
||||
public int X { get; set; }
|
||||
/// <summary>
|
||||
/// The y component
|
||||
/// </summary>
|
||||
public int Y { get; set; }
|
||||
|
||||
public Point(int x, int y)
|
||||
@ -16,6 +25,11 @@ namespace LD_24.Code
|
||||
Y = y;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if 2 points are the same
|
||||
/// </summary>
|
||||
/// <param name="obj">Other point</param>
|
||||
/// <returns>Are the x and y the same</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is Point point &&
|
||||
@ -31,5 +45,9 @@ namespace LD_24.Code
|
||||
return hashCode;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return String.Format("Point({0}, {1})", X, Y);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ using System.Web;
|
||||
namespace LD_24.Code
|
||||
{
|
||||
|
||||
public class TaskUtils
|
||||
public static class TaskUtils
|
||||
{
|
||||
public static BestPizzeriaResult FindBestPizzeria(Map map)
|
||||
{
|
||||
|
90
Recursion/LD_24/Forma1-helper.aspx.cs
Normal file
90
Recursion/LD_24/Forma1-helper.aspx.cs
Normal file
@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
namespace LD_24
|
||||
{
|
||||
public partial class Forma1 : System.Web.UI.Page
|
||||
{
|
||||
/// <summary>
|
||||
/// Put target friends into a bulleted list element
|
||||
/// </summary>
|
||||
/// <param name="list">Target list</param>
|
||||
/// <param name="friends">Target friends</param>
|
||||
private void ShowFriends(BulletedList list, List<Code.Point> friends)
|
||||
{
|
||||
list.Items.Clear();
|
||||
foreach (var friend in friends)
|
||||
{
|
||||
list.Items.Add(String.Format("X = {0}, Y = {1}", friend.X + 1, friend.Y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put best pizzeria result into a label
|
||||
/// </summary>
|
||||
/// <param name="label">Target label</param>
|
||||
/// <param name="result">Target result</param>
|
||||
private void ShowBestPizzeriaResult(Label label, Code.BestPizzeriaResult result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
label.Text = "Neįmanoma";
|
||||
return;
|
||||
}
|
||||
|
||||
label.Text = String.Format("Susitikimo vieta (X = {0}, Y = {1})", result.MeetingSpot.X + 1, result.MeetingSpot.Y + 1);
|
||||
label.Text += "<br />";
|
||||
label.Text += String.Format("Picerija (X = {0}, Y = {1})", result.Pizzeria.X + 1, result.Pizzeria.Y + 1);
|
||||
label.Text += "<br />";
|
||||
label.Text += String.Format("Nueita {0}", result.Cost);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Put a maps tiles into a table
|
||||
/// </summary>
|
||||
/// <param name="table">Target table</param>
|
||||
/// <param name="map">Target map</param>
|
||||
private void ShowMap(Table table, Code.Map map)
|
||||
{
|
||||
table.Rows.Clear();
|
||||
for (int y = 0; y < map.Height; y++)
|
||||
{
|
||||
TableRow row = new TableRow();
|
||||
for (int x = 0; x < map.Width; x++)
|
||||
{
|
||||
TableCell cell = new TableCell();
|
||||
cell.Width = 20;
|
||||
cell.Height = 20;
|
||||
switch (map.Get(x, y))
|
||||
{
|
||||
case Code.MapTile.Empty:
|
||||
cell.Text = ".";
|
||||
break;
|
||||
case Code.MapTile.Pizzeria:
|
||||
cell.Text = "P";
|
||||
break;
|
||||
case Code.MapTile.Friend:
|
||||
cell.Text = "D";
|
||||
break;
|
||||
case Code.MapTile.MeetingSpot:
|
||||
cell.Text = "S";
|
||||
break;
|
||||
case Code.MapTile.Wall:
|
||||
cell.Text = "X";
|
||||
break;
|
||||
default:
|
||||
cell.Text = "?";
|
||||
break;
|
||||
}
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
table.Rows.Add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -8,12 +8,18 @@ using System.Web.UI.WebControls;
|
||||
|
||||
namespace LD_24
|
||||
{
|
||||
|
||||
public partial class Forma1 : System.Web.UI.Page
|
||||
{
|
||||
private string inputFilename;
|
||||
private string outputFilename;
|
||||
private Code.Map map;
|
||||
|
||||
/// <summary>
|
||||
/// Load initial map and show it in the interface
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender element</param>
|
||||
/// <param name="e">Event</param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
inputFilename = Server.MapPath(@"App_Data/U3.txt");
|
||||
@ -23,6 +29,12 @@ namespace LD_24
|
||||
ShowMap(Table1, map);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Find which is the best pizzeria, show it in the interface and output the result
|
||||
/// to a file
|
||||
/// </summary>
|
||||
/// <param name="sender">Sender element</param>
|
||||
/// <param name="e">Event</param>
|
||||
protected void Button1_Click(object sender, EventArgs e)
|
||||
{
|
||||
List<Code.Point> friends = map.FindAll(Code.MapTile.Friend);
|
||||
@ -43,67 +55,5 @@ namespace LD_24
|
||||
Code.InOutUtils.WriteBestPizzeriaResult(writer, result);
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowFriends(BulletedList list, List<Code.Point> friends)
|
||||
{
|
||||
list.Items.Clear();
|
||||
foreach (var friend in friends)
|
||||
{
|
||||
list.Items.Add(String.Format("X = {0}, Y = {1}", friend.X + 1, friend.Y + 1));
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowBestPizzeriaResult(Label label, Code.BestPizzeriaResult result)
|
||||
{
|
||||
if (result == null)
|
||||
{
|
||||
label.Text = "Neįmanoma";
|
||||
return;
|
||||
}
|
||||
|
||||
label.Text = String.Format("Susitikimo vieta (X = {0}, Y = {1})", result.MeetingSpot.X + 1, result.MeetingSpot.Y + 1);
|
||||
label.Text += "<br />";
|
||||
label.Text += String.Format("Picerija (X = {0}, Y = {1})", result.Pizzeria.X + 1, result.Pizzeria.Y + 1);
|
||||
label.Text += "<br />";
|
||||
label.Text += String.Format("Nueita {0}", result.Cost);
|
||||
}
|
||||
|
||||
private void ShowMap(Table table, Code.Map map)
|
||||
{
|
||||
table.Rows.Clear();
|
||||
for (int y = 0; y < map.Height; y++)
|
||||
{
|
||||
TableRow row = new TableRow();
|
||||
for (int x = 0; x < map.Width; x++)
|
||||
{
|
||||
TableCell cell = new TableCell();
|
||||
cell.Width = 20;
|
||||
cell.Height = 20;
|
||||
switch (map.Get(x, y))
|
||||
{
|
||||
case Code.MapTile.Empty:
|
||||
cell.Text = ".";
|
||||
break;
|
||||
case Code.MapTile.Pizzeria:
|
||||
cell.Text = "P";
|
||||
break;
|
||||
case Code.MapTile.Friend:
|
||||
cell.Text = "D";
|
||||
break;
|
||||
case Code.MapTile.MeetingSpot:
|
||||
cell.Text = "S";
|
||||
break;
|
||||
case Code.MapTile.Wall:
|
||||
cell.Text = "X";
|
||||
break;
|
||||
default:
|
||||
cell.Text = "?";
|
||||
break;
|
||||
}
|
||||
row.Cells.Add(cell);
|
||||
}
|
||||
table.Rows.Add(row);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -7,13 +7,13 @@
|
||||
<ProductVersion>
|
||||
</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}</ProjectGuid>
|
||||
<ProjectGuid>{4E9466EF-CDF4-4620-B51E-125F5A014A04}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>LD_24</RootNamespace>
|
||||
<AssemblyName>LD_24</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<Use64BitIISExpress />
|
||||
<IISExpressSSLPort>
|
||||
@ -71,6 +71,11 @@
|
||||
<Content Include="App_Data\Rezultatai.txt" />
|
||||
<Content Include="App_Data\U3.txt" />
|
||||
<Content Include="Forma1.aspx" />
|
||||
<Content Include="interface-scheme.png" />
|
||||
<Content Include="tests\1\inputs\U3.txt" />
|
||||
<Content Include="tests\1\outputs\Rezultatai.txt" />
|
||||
<Content Include="tests\2\inputs\U3.txt" />
|
||||
<Content Include="tests\2\outputs\Rezultatai.txt" />
|
||||
<Content Include="Web.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
@ -80,6 +85,9 @@
|
||||
<Compile Include="Code\MapTile.cs" />
|
||||
<Compile Include="Code\Point.cs" />
|
||||
<Compile Include="Code\TaskUtils.cs" />
|
||||
<Compile Include="Forma1-helper.aspx.cs">
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Forma1.aspx.cs">
|
||||
<DependentUpon>Forma1.aspx</DependentUpon>
|
||||
<SubType>ASPXCodeBehind</SubType>
|
||||
@ -98,7 +106,6 @@
|
||||
<DependentUpon>Web.config</DependentUpon>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
@ -112,9 +119,9 @@
|
||||
<WebProjectProperties>
|
||||
<UseIIS>True</UseIIS>
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>57614</DevelopmentServerPort>
|
||||
<DevelopmentServerPort>51983</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:44363/</IISUrl>
|
||||
<IISUrl>http://localhost:44364/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
|
@ -20,7 +20,7 @@ using System.Runtime.InteropServices;
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("6aab1a29-81e1-4a08-a8c3-9c203c684b8f")]
|
||||
[assembly: Guid("4e9466ef-cdf4-4620-b51e-125f5a014a04")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
|
@ -5,8 +5,8 @@
|
||||
-->
|
||||
<configuration>
|
||||
<system.web>
|
||||
<compilation debug="true" targetFramework="4.7.2" />
|
||||
<httpRuntime targetFramework="4.7.2" />
|
||||
<compilation debug="true" targetFramework="4.8" />
|
||||
<httpRuntime targetFramework="4.8" />
|
||||
<globalization fileEncoding="utf-8" />
|
||||
</system.web>
|
||||
<system.codedom>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net472" />
|
||||
<package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.1" targetFramework="net48" />
|
||||
</packages>
|
@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32210.238
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LD_24", "LD_24\LD_24.csproj", "{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LD_24", "LD_24\LD_24.csproj", "{4E9466EF-CDF4-4620-B51E-125F5A014A04}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -11,10 +11,10 @@ Global
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{6AAB1A29-81E1-4A08-A8C3-9C203C684B8F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{4E9466EF-CDF4-4620-B51E-125F5A014A04}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{4E9466EF-CDF4-4620-B51E-125F5A014A04}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{4E9466EF-CDF4-4620-B51E-125F5A014A04}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{4E9466EF-CDF4-4620-B51E-125F5A014A04}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
Loading…
Reference in New Issue
Block a user