📄 simplegroup.java
字号:
package ergo.util;
// $Id: SimpleGroup.java,v 1.4 1999/08/13 01:20:43 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import ergo.logic.Move;
public class SimpleGroup {
private int color;
private PositionVector positions = new PositionVector();
public int size () { return positions.size(); }
public int color () { return color; }
public boolean isMember (Position pos) {
for (int i = 0; i < positions.size(); i++)
if (pos.equals(positions.elementAt(i)))
return true;
return false;
}
public Position positionAt (int index) { return positions.elementAt(index); }
protected PositionVector liberties = new PositionVector(4);
public SimpleGroup (int color) { this.color = color; }
public int numberOfLiberties () { return liberties.size(); }
public void addPosition (Position pos) {
if (isLiberty(pos))
removeLiberty(pos);
if (!isMember(pos))
positions.addElement(pos);
}
public void removePosition (Position pos) {
for (int i = 0; i < positions.size(); i++)
if (positions.elementAt(i).equals(pos)) {
positions.removeElementAt(i);
addLiberty(pos);
}
}
public void addLiberty (Position lib) {
if (!isLiberty(lib))
liberties.addElement(lib);
}
public void removeLiberty (Position lib) {
for (int i = 0; i < liberties.size(); i++)
if (lib.equals(liberties.elementAt(i))) {
liberties.removeElementAt(i);
return;
}
}
public Position libertyAt (int index) {
return liberties.elementAt(index);
}
public boolean isLiberty (Position pos) {
for (int i = 0; i < liberties.size(); i++)
if (pos.equals(liberties.elementAt(i)))
return true;
return false;
}
public String toString () {
// +++ Should remove this dependency on Move by defining a class
// to represent stone colors.
return ((color == Move.BLACK ? "Black: " : "White: ")
+ positions.toString()
+ " -- " + liberties.toString());
}
// For debugging only
public boolean equals (SimpleGroup other) {
if (numberOfLiberties() != other.numberOfLiberties()
|| size() != other.size())
return false;
else {
for (int i = 0; i < positions.size(); i++)
if (!other.isMember(positions.elementAt(i)))
return false;
for (int i = 0; i < liberties.size(); i++)
if (!other.isLiberty(liberties.elementAt(i)))
return false;
return true;
}
}
} // end class SimpleGroup
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -