Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
LongCTygo committed Jul 2, 2023
1 parent 856ee54 commit a36cff0
Show file tree
Hide file tree
Showing 24 changed files with 2,731 additions and 0 deletions.
7 changes: 7 additions & 0 deletions SoTSolverClassLibrary/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace SoTSolverClassLibrary
{
public class Class1
{

}
}
28 changes: 28 additions & 0 deletions SoTSolverClassLibrary/Constants/ColorConstants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoTSolverClassLibrary.Constants
{
public class ColorConstants
{
//Empty
public static readonly Color EmptyText = Color.Black;
public static readonly Color EmptyBG = Color.White;
//Coal
public static readonly Color CoalText = Color.White;
public static readonly Color CoalBG = Color.DimGray;
//Player
public static readonly Color PlayerText = Color.Black;
public static readonly Color PlayerBG = Color.DodgerBlue;
//Goal
public static readonly Color GoalText = Color.White;
public static readonly Color GoalBG = Color.DodgerBlue;
//Text
public static readonly Color SuccessColor = Color.LimeGreen;
public static readonly Color FailedColor = Color.Red;
}
}
22 changes: 22 additions & 0 deletions SoTSolverClassLibrary/DataAccess/Seed.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoTSolverClassLibrary.DataAccess
{
public class Seed
{
public int SeedValue { get; }
public int MovesRequired { get; }
public bool Obstructed { get; }

public Seed(int seedValue, int movesRequired, bool obstructed)
{
SeedValue = seedValue;
MovesRequired = movesRequired;
Obstructed = obstructed;
}
}
}
83 changes: 83 additions & 0 deletions SoTSolverClassLibrary/DataAccess/SeedDAO.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SoTSolverClassLibrary.DataAccess
{
public class SeedDAO
{
private Random random;
public SeedDAO()
{
random = new Random();
}

public SeedDAO(int randSeed)
{
random = new Random(randSeed);
}

public List<Seed> GetRandomSeeds(int minMoves, int maxMoves, bool allowObstructed, int amount)
{
if (amount <= 0)
{
throw new ArgumentException("Amount must be larger than 0");
}
List<Seed> seeds = new List<Seed>();
using var conn = new SQLiteConnection(@"Data Source=SoTPuzzle.db;New=False;");
using var cmd = conn.CreateCommand();
conn.Open();
cmd.CommandText = "SELECT * FROM Puzzles WHERE moves_required BETWEEN @min AND @max AND obstructed <= @obstructed ORDER BY RANDOM() LIMIT @limit";
//Values
cmd.Parameters.AddWithValue("@min", minMoves);
cmd.Parameters.AddWithValue("@max", maxMoves);
cmd.Parameters.AddWithValue("@obstructed", allowObstructed ? 1 : 0);
cmd.Parameters.AddWithValue("@limit", amount);
using var reader = cmd.ExecuteReader();
while (reader.Read())
{
Seed seed = new Seed(
reader.GetInt32(0),
reader.GetInt32(1),
reader.GetBoolean(2)
);
seeds.Add(seed);
}
return seeds;
}

public Seed? GetRandomSeed(int minMoves, int maxMoves, bool allowObstructed)
{
var seeds = GetRandomSeeds(minMoves, maxMoves, allowObstructed, 1);
if (seeds.Count == 0)
{
return null;
}

return seeds[0];
}

public Seed? GetRandomSeed(int minMoves, int maxMoves)
{
return GetRandomSeed(minMoves, maxMoves, false);
}

public Seed? GetRandomSeed(int moves)
{
return GetRandomSeed(moves, moves, false);
}

public Seed? GetRandomSeed(int moves, bool allowObstructed)
{
return GetRandomSeed(moves, moves, allowObstructed);
}

void Main()
{
GetRandomSeed(5);
}
}
}
Loading

0 comments on commit a36cff0

Please sign in to comment.