Skip to content

Commit

Permalink
Merge pull request #9 from Sofken-natori/add-arrange-line-method
Browse files Browse the repository at this point in the history
Add arrange line method
  • Loading branch information
suzukitasuku authored Oct 15, 2024
2 parents c4db61f + 18ae997 commit f4af867
Show file tree
Hide file tree
Showing 17 changed files with 2,814 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Procon"
]
}
3 changes: 2 additions & 1 deletion 2024ProconTemporary/2024ProconTemporary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

<ItemGroup>
<PackageReference Include="DotNetEnv" Version="3.1.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4"/>
<PackageReference Include="EntryPoint" Version="1.3.0" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
3 changes: 3 additions & 0 deletions 2024ProconTemporary/Com/Networking.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ public static class Networking
static Networking()
{
Env.Load();
ServerIp = Env.GetString("SERVER_IP", "127.0.0.1:3000");
Token = Env.GetString("PROCON_TOKEN");
}


public static HttpClient CreateClient()
{
return new HttpClient();
Expand Down
147 changes: 147 additions & 0 deletions 2024ProconTemporary/Command-Line/BootCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
using EntryPoint;
using System;
using _2024ProconTemporary.ReadableData;
using _2024ProconTemporary.Com;
using _2024ProconTemporary;
using System.Linq;


namespace _2024ProconTemporary.CommandLine.Commands
{
public class BootCommandClient : BaseCliArguments
{
public BootCommandClient() : base("Initialize Command") { }

[OptionParameter(ShortName: 'v', LongName: "view")]
[Help("問題データを表示します")]
public bool isView { get; set; }

[OptionParameter(ShortName: 'm', LongName: "manual")]
[Help("手動で回答を作成するモードに移行します")]
public bool isManual { get; set; }
}

public class BootCommand
{
public void Handle(BootCommandClient args)
{
Console.WriteLine("Booting...");
// 問題データを取得する
Console.WriteLine("Getting Problem Data...");
HttpClient client = Networking.CreateClient();
var problemData = Networking.GetProblemData(client);

if (problemData == null)
{
Console.WriteLine("ERROR: ProblemData Download Failed!");
Console.WriteLine("Please check your network connection and try again.");
return;
}
Console.WriteLine("Done!");

Console.WriteLine("Converting Problem Data...");
// 問題データ、回答データをstringの配列からintの2次元配列に変換する
ReadableProblemData convertedProblemData = new ReadableProblemData(problemData);
Console.WriteLine("Done!");
Console.WriteLine("View Problem Data:");
convertedProblemData.Print();
// 問題データを表示する
if (args.isView)
{
Console.WriteLine("View Problem Data:");
convertedProblemData.Print();
}

AnswerData answerData = Answer.Create();

// 手動で回答を作成するモードに移行する
if (args.isManual)
{
Console.WriteLine("Manual Mode");
Console.WriteLine("Please input answer.");
ManualMode(problemData);
}

else
{
// 自動回答モードに移行する
Console.WriteLine("Automatic Mode");
Console.WriteLine("Calculating Answer...");
// ここで問題データをMainAlgorithmに渡して、回答を計算する(引数はReadableProblemData型)
// Mainalgorithm.MatchCalculate();

Console.WriteLine("Done!");

// 回答結果を表示する(間違っている場所、かかった手数など) 未実装



// これで提出するか聞く
Console.WriteLine("Do you want to submit this answer? (Y/n)");
string input = Console.ReadLine() ?? "";

if (input == "N" || input == "n")
{
// 手動で回答を作成するモードに移行する
Console.WriteLine("transit to Manual Mode");
answerData = ManualMode(problemData);
}

// 回答を提出する
Console.WriteLine("Submitting Answer...");
Networking.SendAnswerData(client, answerData);
Console.WriteLine("Done!");

}
}


/// <summary>
/// 手動で回答を作成するモードに移行する 未実装
/// </summary>
/// <param name="problemData">使用する問題データ</param>
/// <returns></returns>
AnswerData ManualMode(ProblemData problemData)
{
AnswerData answerData = Answer.Create();
Console.WriteLine("Manual Mode");
Console.WriteLine("Please input answer.");

// キー入力を受付、回答を作成する
while (true)
{
Console.WriteLine("Please press key...");

ConsoleKeyInfo key = Console.ReadKey();

if (key.Key == ConsoleKey.Escape)
{
// 終了
Console.WriteLine("Exit Manual Mode");
break;
}

else if (key.Key == ConsoleKey.H)
{
// ヘルプを表示
Console.WriteLine("Help");
}

else if (key.Key == ConsoleKey.Enter)
{

}

}
return answerData;

}

void CompareAnswers(ReadableProblemData problemData, ReadableProblemData answerData)
{

}
}


}
15 changes: 15 additions & 0 deletions 2024ProconTemporary/Command-Line/BootProgram.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using EntryPoint;
using System;
using _2024ProconTemporary.CommandLine.Commands;
using _2024ProconTemporary.Base;
using _2024ProconTemporary.Com;
using System.Security.Cryptography.X509Certificates;

class BootProgram
{

// static void Main(string[] args)
// {
// Cli.Execute<CommandClient>(args);
// }
}
21 changes: 21 additions & 0 deletions 2024ProconTemporary/Command-Line/CommandClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using EntryPoint;
using _2024ProconTemporary.CommandLine.Commands;


namespace _2024ProconTemporary.Base
{
public class CommandClient : BaseCliCommands
{
[DefaultCommand]
[Command("Boot")]
[Help("受け取った問題を解くコマンド")]
public void Boot(string[] args)
{
var options = Cli.Parse<BootCommandClient>(args);
var command = new BootCommand();
command.Handle(options);
}


}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
using System;
using _2024ProconTemporary.Com;
using System.Linq;

namespace _2024ProconTemporary.ReadableData
{
public class ReadableProblemData
{
public ReadableBoardData Board { get; set; }
public ReadableGeneralData General { get; set; }

public ReadableProblemData(ProblemData problemData)
{
Board = new ReadableBoardData(problemData.Board.Width, problemData.Board.Height, problemData.Board.Start, problemData.Board.Goal);
General = new ReadableGeneralData(problemData.General.N, problemData.General.Patterns.Select(p => new ReadableGeneralData.ReadablePatternData(p.P, p.Width, p.Height, p.Cells)).ToList());
}

public void Print()
{
Console.WriteLine("Board Data:");
Console.WriteLine($"Width: {Board.Width}");
Console.WriteLine($"Height: {Board.Height}");
Console.WriteLine("Start:");
foreach (var s in Board.Start)
{
Console.WriteLine(string.Join(" ", s));
}
Console.WriteLine("Goal:");
foreach (var g in Board.Goal)
{
Console.WriteLine(string.Join(" ", g));
}

Console.WriteLine("General Data:");
Console.WriteLine($"N: {General.N}");
Console.WriteLine("Patterns:");
foreach (var p in General.Patterns)
{
Console.WriteLine($"P: {p.P}");
Console.WriteLine($"Width: {p.Width}");
Console.WriteLine($"Height: {p.Height}");
Console.WriteLine("Cells:");
foreach (var c in p.Cells)
{
Console.WriteLine(string.Join(" ", c));
}
}
}

public class ReadableBoardData
{
public int Width { get; set; }
public int Height { get; set; }
public IList<List<int>> Start { get; set; }
public IList<List<int>> Goal { get; set; }
public ReadableBoardData(int width, int height, IList<string> start, IList<string> goal)
{
Width = width;
Height = height;

Start = new List<List<int>>();

foreach (var s in start)
{
var list = new List<int>();
IEnumerable<char> index = s.ToCharArray();
foreach (var c in index)
{
list.Add(c - '0');
}
Start.Add(list);
}

Goal = new List<List<int>>();

foreach (var g in goal)
{
var list = new List<int>();
IEnumerable<char> index = g.ToCharArray();
foreach (var c in index)
{
list.Add(c - '0');
}
Goal.Add(list);
}
}
}

public class ReadableGeneralData
{
public int N;
public IList<ReadablePatternData> Patterns { get; set; }

public ReadableGeneralData(int n, IList<ReadablePatternData> patterns)
{
N = n;
Patterns = patterns;
}

public class ReadablePatternData
{
public int P { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public IList<List<int>> Cells { get; set; }
public ReadablePatternData(int p, int width, int height, IList<string> cells)
{
P = p;
Width = width;
Height = height;

Cells = new List<List<int>>();
foreach (var c in cells)
{
var list = new List<int>();
IEnumerable<char> index = c.ToCharArray();
foreach (var i in index)
{
list.Add(i - '0');
}
Cells.Add(list);
}
}


}
}
}
}
Loading

0 comments on commit f4af867

Please sign in to comment.