Skip to content

Commit

Permalink
[New] Add category zero
Browse files Browse the repository at this point in the history
  • Loading branch information
akinobu1998 committed Apr 3, 2023
1 parent 866d200 commit 91234c3
Show file tree
Hide file tree
Showing 16 changed files with 771 additions and 583 deletions.
308 changes: 154 additions & 154 deletions CommandGenerator/BaseProgram.cs
Original file line number Diff line number Diff line change
@@ -1,90 +1,90 @@
using System;
using System.Collections.Generic;
using System.Threading;

namespace RoboCup.AtHome.CommandGenerator
{
/// <summary>
/// Base class for program control logic
/// </summary>
public abstract class BaseProgram
using System;
using System.Collections.Generic;
using System.Threading;

namespace RoboCup.AtHome.CommandGenerator
{
/// <summary>
/// Base class for program control logic
/// </summary>
public abstract class BaseProgram
{
protected abstract Generator Gen { get; }

/// <summary>
/// Gets user text from console input and displays it in a QR code
/// </summary>
protected void DisplayQRText()
{
Console.WriteLine("Write text for QR code and press INTRO.");
Console.Write("QR Text: ");
ShowQRDialog(Console.ReadLine());
}

/// <summary>
/// Request the user to choose an option for random task generation.
/// </summary>
/// <returns>The user's option.</returns>
protected virtual char GetOption(int opcMin, int opcMax)
{
ConsoleKeyInfo k;
Console.WriteLine("Press Esc to quit, q for QR Code, t for type in a QR, c to clear.");
Console.Write("Enter category {0} to {1}: ", opcMin, opcMax);
do
{
k = Console.ReadKey(true);
} while ((k.Key != ConsoleKey.Escape) && (k.KeyChar != 'q') && (k.KeyChar != 't') && (k.KeyChar != 'c') && ((k.KeyChar < ('0' + opcMin)) || (k.KeyChar > ('0' + opcMax) )));
if (k.Key == ConsoleKey.Escape)
return '\0';
Console.WriteLine(k.KeyChar);
return k.KeyChar;
protected abstract Generator Gen { get; }

/// <summary>
/// Gets user text from console input and displays it in a QR code
/// </summary>
protected void DisplayQRText()
{
Console.WriteLine("Write text for QR code and press INTRO.");
Console.Write("QR Text: ");
ShowQRDialog(Console.ReadLine());
}

/// <summary>
/// Request the user to choose an option for random task generation.
/// </summary>
/// <returns>The user's option.</returns>
protected virtual char GetOption(int opcMin, int opcMax)
{
ConsoleKeyInfo k;
Console.WriteLine("Press Esc to quit, q for QR Code, t for type in a QR, c to clear.");
Console.Write("Enter category {0} to {1}: ", opcMin, opcMax);
do
{
k = Console.ReadKey(true);
} while ((k.Key != ConsoleKey.Escape) && (k.KeyChar != 'q') && (k.KeyChar != 't') && (k.KeyChar != 'c') && ((k.KeyChar < ('0' + opcMin)) || (k.KeyChar > ('0' + opcMax) )));
if (k.Key == ConsoleKey.Escape)
return '\0';
Console.WriteLine(k.KeyChar);
return k.KeyChar;
}

/// <summary>
/// Request the user to choose an option for random task generation.
/// </summary>
/// <returns>The user's option.</returns>
protected abstract char GetOption();

/// <summary>
/// Loads data from lists and storage
/// </summary>
protected void LoadData()
{
Console.Write("Loading objects...");
Gen.LoadObjects();
Console.Write("Loading names...");
Gen.LoadNames();
Console.Write("Loading locations...");
Gen.LoadLocations();
Console.Write("Loading gestures...");
Gen.LoadGestures();
Console.Write("Loading predefined questions...");
Gen.LoadQuestions();
Console.Write("Loading grammars...");
Gen.LoadGrammars();
Gen.ValidateLocations();
}

/// <summary>
/// Prints a task including metadata into the output stream.
/// </summary>
/// <param name="task">The task to be print</param>
protected virtual void PrintTask(Task task)
{
if (task == null)
protected abstract char GetOption();

/// <summary>
/// Loads data from lists and storage
/// </summary>
protected void LoadData()
{
Console.Write("Loading objects...");
Gen.LoadObjects();
Console.Write("Loading names...");
Gen.LoadNames();
Console.Write("Loading locations...");
Gen.LoadLocations();
Console.Write("Loading gestures...");
Gen.LoadGestures();
Console.Write("Loading predefined questions...");
Gen.LoadQuestions();
Console.Write("Loading grammars...");
Gen.LoadGrammars();
Gen.ValidateLocations();
}

/// <summary>
/// Prints a task including metadata into the output stream.
/// </summary>
/// <param name="task">The task to be print</param>
protected virtual void PrintTask(Task task)
{
if (task == null)
return;
string sTask = task.ToString().Trim();
if (sTask.Length < 1)
return;

// switch Console color to white, backuping the previous one
ConsoleColor pc = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
// Prints a === line
string pad = String.Empty.PadRight(Console.BufferWidth - 1, '=');
Console.WriteLine(pad);
return;

// switch Console color to white, backuping the previous one
ConsoleColor pc = Console.ForegroundColor;
Console.ForegroundColor = ConsoleColor.White;
Console.WriteLine();
// Prints a === line
string pad = String.Empty.PadRight(Console.BufferWidth - 1, '=');
Console.WriteLine(pad);
Console.WriteLine();

// Prints task string and metadata
Expand All @@ -97,61 +97,61 @@ protected virtual void PrintTask(Task task)
cut = sTask.LastIndexOf(' ', Console.BufferWidth-1);
Console.WriteLine(sTask.Substring(0, cut));
sTask = sTask.Substring(cut).Trim();
} while (!String.IsNullOrEmpty(sTask));
PrintTaskMetadata(task);
Console.WriteLine();
// Prints another line
Console.WriteLine(pad);
// Restores Console color
Console.ForegroundColor = pc;
Console.WriteLine();
}

/// <summary>
/// Prints the task metadata.
/// </summary>
/// <param name="task">The task object containing metadata to print.</param>
protected void PrintTaskMetadata(Task task)
{
Console.WriteLine();
List<string> remarks = new List<string>();
// Print named metadata
foreach (Token token in task.Tokens)
PrintMetadata(token, remarks);
PrintRemarks(remarks);
}

/// <summary>
/// Prints the metadata of the given Token
/// </summary>
/// <param name="token">The token onject containing the metadata to print</param>
/// <param name="remarks">A list to store all metadata whose token has no name</param>
protected void PrintMetadata(Token token, List<string> remarks)
{
if (token.Metadata.Count < 1) return;
// Store remarks for later
if (String.IsNullOrEmpty(token.Name))
{
remarks.AddRange(token.Metadata);
return;
}
// Print current token metadata
Console.WriteLine("{0}", token.Name);
foreach (string md in token.Metadata)
Console.WriteLine("\t{0}", md);
}

/// <summary>
/// Prints remaining metadata stored in the remarks list
/// </summary>
/// <param name="remarks">List of remarks strings</param>
protected void PrintRemarks(List<string> remarks)
{
if (remarks.Count > 0)
{
Console.WriteLine("remarks");
foreach (string r in remarks)
Console.WriteLine("\t{0}", r);
} while (!String.IsNullOrEmpty(sTask));
PrintTaskMetadata(task);
Console.WriteLine();
// Prints another line
Console.WriteLine(pad);
// Restores Console color
Console.ForegroundColor = pc;
Console.WriteLine();
}

/// <summary>
/// Prints the task metadata.
/// </summary>
/// <param name="task">The task object containing metadata to print.</param>
protected void PrintTaskMetadata(Task task)
{
Console.WriteLine();
List<string> remarks = new List<string>();
// Print named metadata
foreach (Token token in task.Tokens)
PrintMetadata(token, remarks);
PrintRemarks(remarks);
}

/// <summary>
/// Prints the metadata of the given Token
/// </summary>
/// <param name="token">The token onject containing the metadata to print</param>
/// <param name="remarks">A list to store all metadata whose token has no name</param>
protected void PrintMetadata(Token token, List<string> remarks)
{
if (token.Metadata.Count < 1) return;
// Store remarks for later
if (String.IsNullOrEmpty(token.Name))
{
remarks.AddRange(token.Metadata);
return;
}
// Print current token metadata
Console.WriteLine("{0}", token.Name);
foreach (string md in token.Metadata)
Console.WriteLine("\t{0}", md);
}

/// <summary>
/// Prints remaining metadata stored in the remarks list
/// </summary>
/// <param name="remarks">List of remarks strings</param>
protected void PrintRemarks(List<string> remarks)
{
if (remarks.Count > 0)
{
Console.WriteLine("remarks");
foreach (string r in remarks)
Console.WriteLine("\t{0}", r);
}
}

Expand All @@ -175,25 +175,25 @@ public virtual void Run()
/// Executes the user's option
/// </summary>
/// <param name="opc">User option (category).</param>
protected abstract void RunOption(char opc, ref Task task);

/// <summary>
/// When overriden in a derived class initializes the random task Generator and loads data from lists and storage
/// </summary>
protected abstract void Setup();

/// <summary>
/// Creates and displays a QR dialog window with the given text
/// </summary>
/// <param name="text">Thext to show in the QR code</param>
public static void ShowQRDialog(string text)
{
Thread thread = new Thread(new ThreadStart( () => {
RoboCup.AtHome.CommandGenerator.GUI.QRDialog.OpenQRWindow(text);
System.Windows.Forms.Application.Run();
} ));
thread.IsBackground = true;
thread.Start();
}
}
}
protected abstract void RunOption(char opc, ref Task task);

/// <summary>
/// When overriden in a derived class initializes the random task Generator and loads data from lists and storage
/// </summary>
protected abstract void Setup();

/// <summary>
/// Creates and displays a QR dialog window with the given text
/// </summary>
/// <param name="text">Thext to show in the QR code</param>
public static void ShowQRDialog(string text)
{
Thread thread = new Thread(new ThreadStart( () => {
RoboCup.AtHome.CommandGenerator.GUI.QRDialog.OpenQRWindow(text);
System.Windows.Forms.Application.Run();
} ));
thread.IsBackground = true;
thread.Start();
}
}
}
4 changes: 2 additions & 2 deletions CommandGenerator/Category.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Category : INameable
protected SpecificLocation defaultLocation;

/// <summary>
/// Stores the list of objects in the category
/// Stores the Low of objects in the category
/// </summary>
protected Dictionary<string, GPSRObject> objects;

Expand Down Expand Up @@ -112,7 +112,7 @@ public SpecificLocation DefaultLocation {
}

/// <summary>
/// Gets or sets the list of objects in the category.
/// Gets or sets the Low of objects in the category.
/// </summary>
/// <remarks>Use for (de)serialization purposes only</remarks>
[XmlElement("object")]
Expand Down
18 changes: 12 additions & 6 deletions CommandGenerator/DifficultyDegree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,18 @@ public enum DifficultyDegree
/// </summary>
[XmlEnum("none")]
None = 0,
/// <summary>
/// Solving the task requires a minimum effort
/// A task using an element with this attribute is easy to solve
/// </summary>
[XmlEnum("easy")]
Easy = 1,
/// <summary>
/// Solving the task requires less than a minimum effort
/// A task using an element with this attribute is very easy to solve
/// </summary>
[XmlEnum("low")]
Low = 1,
/// <summary>
/// Solving the task requires a minimum effort
/// A task using an element with this attribute is easy to solve
/// </summary>
[XmlEnum("easy")]
Easy = 2,
/// <summary>
/// Solving the task requires a moderate effort
/// A task using an element with this attribute is not so easy to solve
Expand Down
4 changes: 2 additions & 2 deletions CommandGenerator/Gesture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class Gesture : INameable, ITiered
/// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.Gesture"/> class.
/// </summary>
/// <remarks>Intended fo serialiazation purposes only</remarks>
public Gesture () : this("none", DifficultyDegree.Easy){ }
public Gesture () : this("none", DifficultyDegree.Low){ }

/// <summary>
/// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.Gesture"/> class.
/// </summary>
/// <param name="name">The name of the gesture</param>
public Gesture (string name) : this(name, DifficultyDegree.Easy){ }
public Gesture (string name) : this(name, DifficultyDegree.Low){ }

/// <summary>
/// Initializes a new instance of the <see cref="RoboCup.AtHome.CommandGenerator.Gesture"/> class.
Expand Down
Loading

0 comments on commit 91234c3

Please sign in to comment.