Skip to content
Snippets Groups Projects
Commit fd99135d authored by Floris's avatar Floris
Browse files

skyscraper...

parent 59e7a713
No related branches found
No related tags found
No related merge requests found
......@@ -60,19 +60,6 @@ namespace PuzzlePlayer_Namespace
}
// checks if the board is valid and solvable before setting the variable.
public bool setBoardState(int[,] newState)
{
int[,] copy = boardState;
boardState = newState;
if (IsBoardValid(newState) && Solve(false) == SOLUTIONS.UNIQUE)
return true;
else
{
boardState = copy;
return false;
}
}
public abstract void Draw(Graphics gr, Rectangle r);
// a methode for solving the whole board. It uses the private SolveStep methode untill the whole board is solved
......@@ -108,20 +95,7 @@ namespace PuzzlePlayer_Namespace
}
// abstract methode for solving one step
private Move? SolveStep(int[,] currentBoardState)
{
// get a list with all the possible moves
List<Move> moves = GetSolveList(currentBoardState);
// if there are no moves found then null is returned
if (moves.Count == 0)
return null;
// return one of the possible moves
// (if the first one is always chosen than that may lead to expected behavior. For example if the possible moves are checked in a certain order)
Random rnd = new Random();
return moves[rnd.Next(0, moves.Count - 1)];
}
public virtual Point Hint() { return new Point(0, 0); }
// a abstract methode to get a list of all possible moves
protected abstract List<Move> GetSolveList(int[,] boardToSolve);
......
......@@ -10,7 +10,7 @@ namespace PuzzlePlayer_Namespace
{
internal static void Main(string[] args)
{
Application.Run(new PuzzleForm(new Skyscrapers(6)));
Application.Run(new MainForm());
}
}
......
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.IO;
......@@ -9,6 +10,7 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;
using System.Windows.Forms.VisualStyles;
namespace PuzzlePlayer_Namespace
{
......@@ -96,30 +98,7 @@ namespace PuzzlePlayer_Namespace
public override void Generate()
{
boardState = GetClearBoard(boardState.GetLength(0));
candidateState = new string[boardState.GetLength(0), boardState.GetLength(1)];
Random random = new Random();
void RandomFillLine(int direction)
{
List<int> options = new List<int>();
for (int i = 0; i < boardState.GetLength(0) - 2; i++)
options.Add(i + 1);
int deficit = 0;
if (boardState[1, 1] != emptySpace)
{
options.Remove(boardState[1, 1]);
deficit++;
}
for (int i = deficit; i < boardState.GetLength(0) - 2; i++)
{
int index = random.Next(options.Count);
boardState[1 + i * (1 - direction), 1 + i * direction] = options[index];
options.RemoveAt(index);
}
}
RandomFillLine(0);
RandomFillLine(1);
return;
}
public override void TileInput(Point? p, Keys k)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment