?? wzq.java
字號:
continue;
}
// O_X#XO
continue;
}
// O_X#O
continue;
}
// S(x + 2 * mx[i], y + 2 * my[i]) == fi || edge
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY) // #_XO
{
if (S(x - 2 * mx[i], y - 2 * my[i]) == type)
{
if (S(x - 3 * mx[i], y - 3 * my[i]) == EMPTY) // #X#_XO
{
points += THREEBLOCK;
PointBoard[x][y] += THREEBLOCK * multiplier;
continue;
}
if (S(x - 3 * mx[i], y - 3 * my[i]) == type) // XX#_XO
{
points += FOURBLOCKHOLE;
PointBoard[x][y] += FOURBLOCKHOLE * multiplier * blockmult[x][y];
blockmult[x][y]++;
continue;
}
// OX#_XO
continue;
}
if (S(x - 2 * mx[i], y - 2 * my[i]) == EMPTY)
{
if (S(x - 3 * mx[i], y - 3 * my[i]) == EMPTY) // ###_XO
{
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
if (S(x - 3 * mx[i], y - 3 * my[i]) == type) // X##_XO
{
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
// O##_XO
continue;
}
// O#_XO
continue;
}
// if (S(x - 1 * mx[i], y - 1 * my[i]) == type) continue; // Already processed
// O_XO
continue;
}
//-------------------- S(x + 1 * mx[i], y + 1 * my[i]) != type
if (S(x + 1 * mx[i], y + 1 * my[i]) == EMPTY && S(x + 2 * mx[i], y + 2 * my[i]) == type) // _#X
{
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY && S(x + 3 * mx[i], y + 3 * my[i]) == EMPTY) // #_#X#
{
points += TWOHOLE;
PointBoard[x][y] += TWOHOLE * multiplier;
continue;
}
if (S(x - 1 * mx[i], y - 1 * my[i]) == type) continue; // X_#X# Already processed
if (S(x + 3 * mx[i], y + 3 * my[i]) == type) // _#XX
{
if (S(x - 1 * mx[i], y - 1 * my[i]) == type) continue; // X_#XX // Already processed
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY) // #_#XX
{
if (S(x + 4 * mx[i], y + 4 * my[i]) == EMPTY) // #_#XX#
{
points += THREEHOLE;
PointBoard[x][y] += THREEHOLE * multiplier;
continue;
}
if (S(x + 4 * mx[i], y + 4 * my[i]) == type) // #_#XXX
{
points += FOURBLOCKHOLE;
PointBoard[x][y] += FOURBLOCKHOLE * multiplier * blockmult[x][y];
blockmult[x][y]++;
continue;
}
// #_#XXO
points += THREEBLOCK;
PointBoard[x][y] += THREEBLOCK * multiplier;
continue;
}
// O_#XX
points += THREEBLOCK;
PointBoard[x][y] += THREEBLOCK * multiplier;
continue;
}
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY) // #_#XO
{
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
// O_#X#
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
if (S(x + 1 * mx[i], y + 1 * my[i]) == EMPTY && S(x + 2 * mx[i], y + 2 * my[i]) == EMPTY && S(x + 3 * mx[i], y + 3 * my[i]) == type) // _##X
{
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY && S(x + 4 * mx[i], y + 4 * my[i]) == EMPTY) // #_##X#
{
points += TWOHOLE;
PointBoard[x][y] += TWOHOLE * multiplier;
continue;
}
if (S(x - 1 * mx[i], y - 1 * my[i]) == type) continue; // X_##X# // Already processed
if (S(x + 4 * mx[i], y + 4 * my[i]) == type) // _##XX
{
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY) // #_##XX
{
points += TWOHOLE;
PointBoard[x][y] += TWOHOLE * multiplier;
continue;
}
if (S(x - 1 * mx[i], y - 1 * my[i]) == type) continue; // X_##XX // Already processed
// O_##XX
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
if (S(x - 1 * mx[i], y - 1 * my[i]) == EMPTY) // #_##XO
{
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
// O_##X#
points += TWOBLOCK;
PointBoard[x][y] += TWOBLOCK * multiplier;
continue;
}
}
}
return points;
}
void
MakeMark(int x, int y, char type)
{
if (x < startx) startx = x;
if (x > endx) endx = x;
if (y < starty) starty = y;
if (y > endy) endy = y;
if (startx < 4) startx = 4;
if (starty < 4) starty = 4;
if (endx > 27) endx = 27;
if (endy > 27) endy = 27;
Board[x][y][0] = type;
}
void
ComputerMove()
{
int xpoints, opoints;
float agression;
int status, maxstat = -300000;
int x, y, max[] = { -300000, -300000 };
int bestx[] = { 1, 1 }, besty[] = { 1, 1 };
int bx = 1, by = 1, min = 300000;
int besx = 1, besy = 1;
int i, i2;
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
opoints = Analyze(MARKO, 1);
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
xpoints = Analyze(MARKX, 1);
if (xpoints != 0)
{
agression = (float)opoints / (float)xpoints;
agression *= 3.5;
}
else agression = 10;
opoints = Analyze(MARKO, agression);
for (x = startx - 4; x < endx + 4; x++)
for (y = starty - 4; y < endy + 4; y++)
if (PointBoard[x][y] >= max[0])
{
if (PointBoard[x][y] > max[0] || Math.random() < 0.5)
{
max[0] = PointBoard[x][y];
bestx[0] = x;
besty[0] = y;
}
}
/* for (x = startx - 4; x < endx + 4; x++)
for (y = starty - 4; y < endy + 4; y++)
{
for (i = 0; i < 2; i++)
if (PointBoard[x][y] > max[i])
{
for (i2 = 1; i2 > i; i2--)
{
max[i2] = max[i2 - 1];
bestx[i2] = bestx[i2 - 1];
besty[i2] = besty[i2 - 1];
}
max[i] = PointBoard[x][y];
bestx[i] = x; besty[i] = y;
i = 2;
}
}
CopyBoard(0, 1);
for (i = 0; i < 2; i++)
{
Board[bestx[i]][besty[i]][0] = MARKO;
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
xpoints = Analyze(MARKX, 1);
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
opoints = Analyze(MARKO, 1);
agression = (float)xpoints / (float)opoints;
agression *= 3.5;
Analyze(MARKX, agression);
max[0] = -300000;
for (x = startx - 4; x < endx + 4; x++)
for (y = starty - 4; y < endy + 4; y++)
{
if (PointBoard[x][y] > max[0])
{
max[0] = PointBoard[x][y];
besx = x; besy = y;
}
}
Board[besx][besy][0] = MARKX;
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
opoints = Analyze(MARKO, 1) / 2;
if (ChkWin(0) == MARKO) opoints += 150000;
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
PointBoard[x][y] = 0;
xpoints = Analyze(MARKX, 1);
if (ChkWin(0) == MARKX) xpoints += 150000;
status = opoints - xpoints;
status2[i] = status;
if (status > maxstat)
{
maxstat = status;
bx = bestx[i];
by = besty[i];
fx = besx; fy = besy;
}
CopyBoard(1, 0);
}
*/
MakeMark(bestx[0], besty[0], MARKO);
}
Image notImage;
Image crossImage;
Image Menu;
Image YouLost;
Image YouWon;
Image Waiting;
Image Playing;
public void
init()
{
notImage = getImage(getCodeBase(), "images/not.gif");
crossImage = getImage(getCodeBase(), "images/cross.gif");
Menu = getImage(getCodeBase(), "images/menu.gif");
YouLost = getImage(getCodeBase(), "images/youlost.gif");
YouWon = getImage(getCodeBase(), "images/youwon.gif");
Waiting = getImage(getCodeBase(), "images/waiting.gif");
Playing = getImage(getCodeBase(), "images/playing.gif");
setBackground(Color.white);
}
public void
NewGame()
{
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
Board[x][y][0] = EMPTY;
for (x = 0; x < 32; x++)
Board[x][0][0] = EDGE;
for (y = 0; y < 32; y++)
Board[0][y][0] = EDGE;
for (x = 0; x < 32; x++)
Board[x][31][0] = EDGE;
for (y = 0; y < 32; y++)
Board[31][y][0] = EDGE;
Board[15][15][0] = MARKO;
picturestatus = PLAYING;
cleararea = 1;
startx = 15; starty = 15; endx = 15; endy = 15;
repaint();
}
public void
paint (Graphics g)
{
g.setColor(Color.black);
for (x = 0; x < 31; x++)
g.drawLine(13 * x, 0, 13 * x, 389);
for (y = 0; y < 31; y++)
g.drawLine(0, 13 * y, 389, 13 * y);
g.drawImage(Menu, 393, 2, this);
if (picturestatus == WAITING) g.drawImage(Waiting, 393, 240, this);
if (picturestatus == PLAYING) g.drawImage(Playing, 393, 240, this);
if (picturestatus == YOUWON) g.drawImage(YouWon, 393, 240, this);
if (picturestatus == YOULOST) g.drawImage(YouLost, 393, 240, this);
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
{
if (Board[x][y][0] == MARKX) g.drawImage(crossImage, (x - 1) * 13 + 1, (y - 1) * 13 + 1, this);
if (Board[x][y][0] == MARKO) g.drawImage(notImage, (x - 1) * 13 + 1, (y - 1) * 13 + 1, this);
}
}
public void
update (Graphics g)
{
if (cleararea == 1)
{
cleararea = 0;
g.setColor(Color.white);
g.fillRect(0, 0, 600, 400);
g.setColor(Color.black);
for (x = 0; x < 31; x++)
g.drawLine(13 * x, 0, 13 * x, 389);
for (y = 0; y < 31; y++)
g.drawLine(0, 13 * y, 389, 13 * y);
g.drawImage(Menu, 393, 2, this);
if (picturestatus == WAITING) g.drawImage(Waiting, 393, 240, this);
if (picturestatus == PLAYING) g.drawImage(Playing, 393, 240, this);
}
if (picturestatus == YOUWON) g.drawImage(YouWon, 393, 240, this);
if (picturestatus == YOULOST) g.drawImage(YouLost, 393, 240, this);
/* g.setColor(Color.white);
g.fillRect(0, 0, 100, 60);
g.setColor(Color.black);
g.drawString("o = " + status2[0], 0, 30);
g.drawString("x = " + status2[1], 0, 40);*/
for (x = 1; x < 31; x++)
for (y = 1; y < 31; y++)
{
if (Board[x][y][0] == MARKX) g.drawImage(crossImage, (x - 1) * 13 + 1, (y - 1) * 13 + 1, this);
if (Board[x][y][0] == MARKO) g.drawImage(notImage, (x - 1) * 13 + 1, (y - 1) * 13 + 1, this);
}
}
public boolean
mouseUp(Event evt, int x, int y)
{
switch (status)
{
case NOTPLAYING:
if (x > 56 + 393 && y > 114 + 2 && x < 151 + 393 && y < 162 + 2)
{
play(getCodeBase(), "audio/joy.au");
NewGame();
repaint();
status = PLAYING;
}
break;
default:
// Figure out the row/colum
Dimension d = size();
int c = x / 13;
int r = y / 13;
if (yourMove(c + 1, r + 1))
{
repaint();
ChkWin(1);
if (status == PLAYING)
{
ComputerMove();
ChkWin(1);
}
}
else play(getCodeBase(), "audio/beep.au");
}
return true;
}
public
String getAppletInfo()
{
return "Connect Five by Staffan Ekvall";
}
}
/* if (PointBoard[x][y] >= max)
{
if (PointBoard[x][y] > max || Math.random() < 0.5)
{
max = PointBoard[x][y];
bestx = x;
besty = y;
}
}*/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -