/
Form1.cs
104 lines (95 loc) · 2.93 KB
/
Form1.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace Reversi
{
public partial class Form1 : Form
{
Board board;
bool flag = false;
private bool IsDrawHelp = true;
public Form1()
{
InitializeComponent();
panel1.Width = 8*80;
panel1.Height = 8*80;
InitBoard();
}
private void InitBoard()
{
label2.Text = "2";
label1.Text = "2";
board = new Board();
board.Draw(panel1, true, 1);
}
private void panel1_Paint(object sender, PaintEventArgs e)
{
board.Draw(e.Graphics, false, 0);
}
private void DoBestStep()
{
List<int[]> l = board.GetEnableSteps(-1);
int j = 0;
int max = -Int32.MaxValue;
for (int i = 0; i < l.Count; i++)
{
Board cp = board.Copy();
cp.AddFig(l[i][1], l[i][0], -1, true);
int res = Board.GetBestStep(1, max, Int32.MaxValue, 0, cp, panel1);
if (max < res)
{
j = i;
max = res;
}
}
if (l.Count > j)
board.AddFig(l[j][1], l[j][0], -1, true);
}
private void CompStep()
{
do
{
DoBestStep();
} while (board.GetEnableSteps(1).Count == 0 && board.GetEnableSteps(-1).Count > 0);
board.Draw(panel1, IsDrawHelp, 1);
int PlayerSteps = board.GetEnableSteps(1).Count;
if (PlayerSteps == 0)
{
if (board.CompFig > board.PlayersFig)
MessageBox.Show("ÏÎÐÀÆÅÍÈÅ!!!");
else
{
if (board.CompFig != board.PlayersFig)
MessageBox.Show("ÏÎÁÅÄÀ!!!");
else
MessageBox.Show("ÍÈ×Üß!!!");
}
}
flag = false;
ShowRes();
}
private void ShowRes()
{
label1.Text = board.PlayersFig.ToString();
label2.Text = board.CompFig.ToString();
}
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
if (flag) return;
int x = e.X / Board.RectWidth;
int y = e.Y / Board.RectWidth;
if (board.AddFig(x, y, 1, true) > 0)
{
flag = true;
board.Draw(panel1, false, -1);
CompStep();
ShowRes();
}
}
private void button1_Click(object sender, EventArgs e)
{
InitBoard();
board.Draw(panel1, IsDrawHelp, 1);
}
}
}