-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUserControl_Need.cs
73 lines (64 loc) · 1.89 KB
/
UserControl_Need.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace N_Puzzle_Game
{
public class UserControl_Need : UserControl
{
public Timer t;
public List<string> rand_states = new List<string>();
public int btn_length = 0, w_length = 0, N = 0;
public int x { set; get; }
public int y { set; get; }
public void load()
{
string path = @"Files\input4_4.in";
var lines = File.ReadLines(path);
foreach (var line in lines)
rand_states.Add(line.ToString());
}
public string state { set; get; }
public string suffle(string p)
{
Random rand = new Random();
char[] state = p.ToCharArray();
for (int i = 0; i < p.Length - 1; i++)
{
int x = rand.Next(i + 1, p.Length);
char c = state[i];
state[i] = state[x];
state[x] = c;
}
return new string(state);
}
public bool is_solvable(string state)
{
int ans = 0;
for (int i = 0; i < state.Length - 1; i++)
for (int j = i + 1; j < state.Length; j++)
if (state[j] > state[i] && state[i] != 48)
ans += 1;
return (ans % 2 == 0);
}
public string get_state(int size)
{
string ans = "";
for (char i = '0'; i < '0' + size; i++)
ans += i;
return suffle(ans);
}
public void start()
{
t.Start();
}
public string random_state()
{
Random rand = new Random();
return rand_states[rand.Next(0, rand_states.Count)];
}
}
}