id stringlengths 36 36 | text stringlengths 1 1.25M |
|---|---|
c9be8321-aa42-4ef9-9b34-aa0cc78573b8 | public PasStartowy(String federateName) {
super(federateName);
} |
fe3936a2-1a07-44c3-88d2-03efd585f5d9 | @Override
public void federateBody() throws RTIexception {
//publish obiektu pasa
int pasHandle = rti.getObjectClassHandle(Constants.OBIEKT_PAS_STARTOWY);
int samolotHandle = rti.getAttributeHandle("samolot", pasHandle);
AttributeHandleSet attributes = RtiFactoryFactory.getRtiFactory().createAttributeHandleSet();
attributes.add(samolotHandle);
rti.publishObjectClass(pasHandle, attributes);
int pasStartowyHandle = rti.registerObjectInstance(pasHandle);
//rejestracja na interkacje z wieza
int intZmianaPasa = rti.getInteractionClassHandle(Constants.INTERKACJA_ZMIANA_PASA);
rti.subscribeInteractionClass(intZmianaPasa);
advanceTime(6.0);
while (!WiezaKontrolna.DONE || !Samolot.DONE || !PasStartowy.DONE) {
if (DONE || (samolotPrev == -1)) {
DONE = true;
}
Integer samolot = ((PasStartowyAmbasador) ambasador).getSamolot();
if (samolot != samolotPrev) {
zmienStatusPasa(pasStartowyHandle, samolot);
}
advanceTime(1.0);
samolotPrev = samolot;
}
deleteObject(pasStartowyHandle);
} |
8e58e366-36a9-4180-954e-0ed80dee487f | private void zmienStatusPasa(int pasStartowyHandle, int samolot) throws RTIexception {
SuppliedAttributes attributes = RtiFactoryFactory.getRtiFactory().createSuppliedAttributes();
byte[] samolotValue = EncodingHelpers.encodeString("samolot:" + samolot);
int classHandle = rti.getObjectClass(pasStartowyHandle);
int samolotHandle = rti.getAttributeHandle("samolot", classHandle);
attributes.add(samolotHandle, samolotValue);
LogicalTime time = convertTime(ambasador.federateTime + ambasador.federateLookahead);
rti.updateAttributeValues(pasStartowyHandle, attributes, generateTag(), time);
} |
6c4d46f5-e581-4143-81ed-f4cd46a5a428 | @Override
public boolean allFederatesReady() {
return WiezaKontrolna.READY && Samolot.READY && PasStartowy.READY && Statystyka.READY;
} |
f7dddb3c-0d40-4c53-b3ed-71f98d532781 | @Override
public void imReady() {
READY = true;
} |
2588f549-c0de-4687-8097-2533116f1a72 | public PasStartowyAmbasador(String ambasadorName) {
super(ambasadorName);
} |
2a21f72f-d3f1-4736-9fb7-36fa5e63dda3 | @Override
public void handleInteraction(int interactionClass, double time, ReceivedInteraction theInteraction) {
try {
samolot = Utils.getIntValue(theInteraction.getValue(0));
if (samolot > 0) {
log("Rezerwacja dla: " + samolot);
}
} catch (ArrayIndexOutOfBounds ex) {
}
} |
f3ba1ebf-e5bf-4936-b5c2-28146d22a5c9 | @Override
public void handleObjectParamsChanged(int theObject, double time, ReflectedAttributes theAttributes) {
} |
59a8d1fe-2149-41cd-8c80-2bdd911faa45 | public Integer getSamolot() {
return samolot;
} |
c2064c7b-d1f8-45a2-b2d2-fc077cac3a88 | public void setSamolot(Integer samolot) {
this.samolot = samolot;
} |
fc01ddcd-4e44-4d0c-9109-319be89aa136 | public SamolotAmbasador(String ambasadorName) {
super(ambasadorName);
statusMap = new HashMap<Integer, Constants.AkcjaSamolotuEnum>();
czySpecjalnyMap = new HashMap<Integer, Boolean>();
} |
959837ad-0d40-453c-b525-70eefbfd1df5 | @Override
public void handleInteraction(int interactionClass, double time, ReceivedInteraction interaction) {
} |
f031e1e6-dc7e-42de-a932-127df20d6b0a | @Override
public void handleObjectParamsChanged(int theObject, double time, ReflectedAttributes theAttributes) {
try {
int samolot = Utils.getIntValue(theAttributes.getValue(0));
samolotDoObslugi = samolot;
if (samolot > 0) {
log("Samolot zajmuje pas: " + samolot);
}
} catch (Exception ex) {
}
} |
129228ab-d9b2-422c-bcf9-8ab5aeb26992 | public Map<Integer, AkcjaSamolotuEnum> getStatusMap() {
return statusMap;
} |
21861e67-d38f-4ef0-869a-af4a6febd928 | public Map<Integer, Boolean> getCzySpecjalnyMap() {
return czySpecjalnyMap;
} |
d203216f-9126-48ae-9c6d-a944c79fc0b9 | public Integer getSamolotDoObslugi() {
return samolotDoObslugi;
} |
2339203c-3cfa-4fa1-8f30-552cda0a47de | void setSamolotDoObslugi(int samolotDoObslugi) {
this.samolotDoObslugi = samolotDoObslugi;
} |
9e6cceca-fdd4-482b-90b5-3f7eb9f7f99d | @Test
public void test() throws Exception {
final String challenge = recaptcha.createChallenge(RECAPTCHA_PUBLIC_KEY);
assertNotNull(challenge);
final String imageUrl = recaptcha.getImageUrl(challenge);
assertNotNull(imageUrl);
} |
9cf8c0d9-f759-430a-9824-c02c07cb7b58 | @Override
public String solve(String imageUrl) {
return "123 456";
} |
7de5d651-ed32-48e1-a9d8-69b28f1bf730 | @Test
public void testLoginWrongCaptcha() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, wrongRecaptchaSolver);
try {
freebitcoin.login(BITCOIN_ADDRESS, PASSWORD);
fail("Expected exception.");
} catch (FreebitcoinException e) {
// Expected exception
assertEquals("e4", e.getMessage());
}
} |
e1bae564-b77f-43ef-b409-6234ae3faa9b | @Test
public void testLoginWrongPassword() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, manualRecaptchaSolver);
try {
freebitcoin.login(BITCOIN_ADDRESS, PASSWORD + "e");
fail("Expected exception.");
} catch (FreebitcoinException e) {
// Expected exception
assertEquals("e3", e.getMessage());
}
} |
530d1759-e14d-4f5a-998f-45d0ac1bf7d9 | @Test
public void testLoginSuccess() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, manualRecaptchaSolver);
freebitcoin.login(BITCOIN_ADDRESS, PASSWORD);
} |
2712e27d-7bd8-4412-9052-10ff478541ec | @Test
public void testFreePlayWrongCaptcha() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, wrongRecaptchaSolver);
try {
freebitcoin.freePlay(BITCOIN_ADDRESS, TOKEN);
fail("Expected exception.");
} catch (FreebitcoinException e) {
// Expected exception
assertEquals("e2", e.getMessage());
}
} |
bcdc6c2b-296f-42d3-bf33-ec6be86bf734 | @Test
public void testFreePlayWrongToken() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, wrongRecaptchaSolver);
try {
freebitcoin.freePlay(BITCOIN_ADDRESS, TOKEN + "e");
fail("Expected exception.");
} catch (FreebitcoinException e) {
// Expected exception
assertEquals("e4", e.getMessage());
}
} |
8ec2111e-903f-4f58-a953-b4b9543c5dbe | @Test
public void testFreeSuccess() throws Exception {
final FreebitcoinClient freebitcoin = new FreebitcoinClient(requestFactory, 5000, 5000, manualRecaptchaSolver);
try {
freebitcoin.freePlay(BITCOIN_ADDRESS, TOKEN);
} catch (FreebitcoinException e) {
// "e3:2918" means "must wait 2918 more seconds"
if (!e.getMessage().startsWith("e3:")) {
throw e;
}
}
} |
72265694-bb78-4f6b-b943-6c622274ef84 | private Endpoint(String url) {
this.url = url;
} |
a34c3977-134f-4931-9158-637f4ce0f004 | public RecaptchaClient(HttpRequestFactory requestFactory, Integer connectTimeout, Integer readTimeout, Endpoint endpoint) {
this.requestFactory = requestFactory;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
this.endpoint = endpoint;
} |
ba73809f-5e61-4577-866f-b703ec41a649 | public String createChallenge(String publicKey) throws IOException {
final HttpRequest request = requestFactory.buildGetRequest(new GenericUrl(
endpoint.url + "challenge?k=" + encode(publicKey)));
if (connectTimeout != null) {
request.setConnectTimeout(connectTimeout);
}
if (readTimeout != null) {
request.setConnectTimeout(readTimeout);
}
final HttpResponse response = request.execute();
try {
final BufferedReader br = new BufferedReader(new InputStreamReader(response.getContent(), "UTF-8"));
try {
String line;
while ((line = br.readLine()) != null) {
final Matcher matcher = challengePattern.matcher(line);
if (!matcher.matches()) {
continue;
}
return matcher.group(1);
}
return null; // TODO: throw exception
} finally {
br.close();
}
} finally {
response.ignore();
}
} |
80e1b874-1352-4a7a-9418-d2a80043d255 | public String getImageUrl(String challenge) {
return endpoint.url + "image?c=" + encode(challenge);
} |
b4373ab8-83f6-4e36-99ef-5d6d3dad09e4 | private static String encode(String s) {
try {
return URLEncoder.encode(s, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
} |
96c8a038-a8f0-449c-ad05-9a70175cf187 | @Override
public int read(byte[] b) throws IOException {
return System.in.read(b);
} |
7bb76b60-eb27-419a-a91c-d7c737794e66 | @Override
public int read(byte[] b, int off, int len) throws IOException {
return System.in.read(b, off, len);
} |
aeb03a76-e25c-4712-955b-4b2275d7b893 | @Override
public long skip(long n) throws IOException {
return System.in.skip(n);
} |
4c0e3cfa-b276-40a0-8642-2b7e5a16781f | @Override
public int available() throws IOException {
return System.in.available();
} |
3df91ac0-6bfd-4e34-aabf-ff2293136976 | @Override
public synchronized void mark(int readlimit) {
System.in.mark(readlimit);
} |
ac45561f-5cd8-49ea-a125-b130703af34b | @Override
public synchronized void reset() throws IOException {
System.in.reset();
} |
f94caf4c-6a13-44ae-99b2-7c63ccdcebc2 | @Override
public boolean markSupported() {
return System.in.markSupported();
} |
d9cd47b9-fdbf-4f7e-855f-8f729ced93be | @Override
public int read() throws IOException {
return System.in.read();
} |
7ce27fe4-dfd8-43c2-9e76-67ac2c7f94a8 | @Override
public String solve(String imageUrl) {
System.out.print("Solve: " + imageUrl);
final Scanner scanner = new Scanner(nonClosableSystemIn);
try {
return scanner.nextLine();
} finally {
scanner.close();
}
} |
e0d1c3b6-1266-4298-bb2a-db817b1f489f | public String solve(String imageUrl); |
32689a62-fa68-4d36-94ca-8c7630c95297 | public FreebitcoinClient(HttpRequestFactory requestFactory, Integer connectTimeout, Integer readTimeout,
CaptchaSolver captchaSolver) {
this.requestFactory = requestFactory;
this.connectTimeout = connectTimeout;
this.readTimeout = readTimeout;
this.captchaSolver = captchaSolver;
recaptcha = new RecaptchaClient(requestFactory, connectTimeout, readTimeout, Endpoint.HTTPS);
} |
41bbc22d-7982-4f7c-b2e3-0146782663af | public String login(String btcAddress, String password) throws IOException, FreebitcoinException {
final String recaptchaChallenge = recaptcha.createChallenge(RECAPTCHA_PUBLIC_KEY);
final String recaptchaResponse = captchaSolver.solve(recaptcha.getImageUrl(recaptchaChallenge));
final Map<String, String> params = new HashMap<String, String>();
params.put("op", "login");
params.put("btc_address", btcAddress);
params.put("password", password);
params.put("recaptcha_challenge_field", recaptchaChallenge);
params.put("recaptcha_response_field", recaptchaResponse);
final HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(ENDPOINT), new UrlEncodedContent(params));
if (connectTimeout != null) {
request.setConnectTimeout(connectTimeout);
}
if (readTimeout != null) {
request.setConnectTimeout(readTimeout);
}
final HttpResponse response = request.execute();
try {
final String responseText = readFully(response.getContent());
final String[] parts = responseText.split(":");
if ((parts.length != 3) || (!"s1".equals(parts[0]))) {
throw new FreebitcoinException(responseText);
}
return parts[2];
} finally {
response.ignore();
}
} |
bdb6dc70-57b6-4bb2-b44d-d539d18e12e7 | private static String randomFingerprint() {
final StringBuilder builder = new StringBuilder();
for (int i = 0; i < 32; ++i) {
builder.append(Integer.toString(rand.nextInt(16), 16));
}
return builder.toString();
} |
1e41f937-0cc8-4b4e-b4be-584cf3795454 | public FreePlayResult freePlay(String btcAddress, String token) throws IOException, FreebitcoinException {
final String recaptchaChallenge = recaptcha.createChallenge(RECAPTCHA_PUBLIC_KEY);
final String recaptchaResponse = captchaSolver.solve(recaptcha.getImageUrl(recaptchaChallenge));
final Map<String, String> params = new HashMap<String, String>();
params.put("op", "free_play");
params.put("recaptcha_challenge_field", recaptchaChallenge);
params.put("recaptcha_response_field", recaptchaResponse);
params.put("fingerprint", randomFingerprint());
final HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(ENDPOINT), new UrlEncodedContent(params));
if (connectTimeout != null) {
request.setConnectTimeout(connectTimeout);
}
if (readTimeout != null) {
request.setConnectTimeout(readTimeout);
}
request.getHeaders().setCookie("btc_address=" + btcAddress + "; password=" + token);
final HttpResponse response = request.execute();
try {
final String responseText = readFully(response.getContent());
final String[] parts = responseText.split(":");
if ((parts.length < 5) || (!"s1".equals(parts[0]))) {
throw new FreebitcoinException(responseText);
}
return new FreePlayResult(Integer.parseInt(parts[1]), Double.parseDouble(parts[2]),
Double.parseDouble(parts[3]), Long.parseLong(parts[4]));
} finally {
response.ignore();
}
} |
ccfe9271-1747-468e-85f6-a1c88eb59f01 | private static String readFully(InputStream is) throws IOException {
final byte[] buffer = new byte[1024*64];
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
int numRead;
while ((numRead = is.read(buffer)) != -1) {
baos.write(buffer, 0, numRead);
}
return new String(baos.toByteArray(), "UTF-8");
} |
b26b8efd-5ecc-43be-a3d7-00cc76e7b580 | public FreebitcoinException(String message) {
super(message);
} |
df86fdf0-fc03-4682-b265-44dd802f390b | public FreebitcoinException(String message, Throwable cause) {
super(message, cause);
} |
9c94630a-4430-469e-9a7b-5172c0874940 | public FreePlayResult(int roll, double balance, double payout, long timestamp) {
this.roll = roll;
this.balance = balance;
this.payout = payout;
this.timestamp = timestamp;
} |
7496ebed-a30e-4242-8f39-81b182c043bc | public Brain(NineMM game) {
this.game = game;
} |
2f213224-06b1-4937-be89-d249164c1511 | public void setStone(Node[] nodes, int type) {
ArrayList<Node> mynodes = new ArrayList<Node>();
ArrayList<Node> enemynodes = new ArrayList<Node>();
ArrayList<Node> freenodes = new ArrayList<Node>();
boolean mill_created = false;
Node selectedNode = null;
for (Node n : nodes) {
if (n.getIsBusy() == 0) {
freenodes.add(n);
continue;
}
if (n.getIsBusy() == type) {
mynodes.add(n);
continue;
}
enemynodes.add(n);
}
selectedNode = freenodes.get((int) (Math.random() * freenodes.size()));
// check for max freenodes
Node goodChoice = findMaxFreeNodes(freenodes);
if (goodChoice != null)
selectedNode = goodChoice;
// if there is a free place beneath my token, take it
for (Node n : mynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
for(Node l : m.getNeighbours()){
if(freenodes.contains(l) && (l.location.x == n.location.x || l.location.y == m.location.y)){
selectedNode = m;
}
}
}
}
}
for (Node n : enemynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
for(Node l : m.getNeighbours()){
if(freenodes.contains(l) && ((l.location.x == m.location.x && l.location.x == n.location.x)||(l.location.y == m.location.y && l.location.y == n.location.y))){
for(Node k : l.getNeighbours()){
if(freenodes.contains(k) && !k.getId().contains(m.getId())){
for(Node j : k.getNeighbours()){
if(enemynodes.contains(j) && ((j.location.x == k.location.x && j.location.x == l.location.x)||(j.location.y == k.location.y && j.location.y == l.location.y))){
selectedNode = l;
}
}
}
}
}
}
}
}
}
// check if the enemy has a mill draw
goodChoice = findMillDraw(enemynodes, freenodes);
if (goodChoice != null)
selectedNode = goodChoice;
// check if we have a mill draw
goodChoice = findMillDraw(mynodes, freenodes);
if (goodChoice != null){
selectedNode = goodChoice;
mill_created = true;
}
//System.out.println("AI: OK, I want to set " + selectedNode.getId());
game.setStones(selectedNode.location);
if(mill_created){
deleteStone(nodes,type);
}
} |
5a515d03-afed-4e40-a8fc-14268dec6ebb | public void moveStone(Node[] nodes, int type) {
Node[] move = new Node[2];
StateOfPlay currentStateOfPlay = new StateOfPlay(null, nodes,null, type,0,1);
currentStateOfPlay.generatePossibilities();
for(StateOfPlay play : currentStateOfPlay.getChildren()){
System.out.println(play.getOriginMove()[0].getId() + " to "+ play.getOriginMove()[1].getId()+",val "+play.getValue());
if(play.getRememberDeletion()!=null){
System.out.println(play.getRememberDeletion().getId());
}
}
StateOfPlay potentialStateOfPlay = currentStateOfPlay.calculateBestEffort();
move = potentialStateOfPlay.getOriginMove();
//System.out.println("I want to move from " + move[0].getId() + " to " + move[1].getId());
game.doSomething(move[0].location);
game.setStones(move[1].location);
if(potentialStateOfPlay.deleteSomething()){
deleteStone(nodes,type);
}
} |
d9b293ef-8961-4f30-a72f-de3aa03cc1f9 | public void jumpStone(Node[] nodes, int type) {
System.out.println("AI: Jump, jump");
ArrayList<Node> mynodes = new ArrayList<Node>();
ArrayList<Node> enemynodes = new ArrayList<Node>();
ArrayList<Node> freenodes = new ArrayList<Node>();
boolean mill_created = false;
Node sourceNode = null;
Node destinationNode = null;
for (Node n : nodes) {
if (n.getIsBusy() == 0) {
freenodes.add(n);
continue;
}
if (n.getIsBusy() == type) {
mynodes.add(n);
continue;
}
enemynodes.add(n);
}
int num_neigh_glob = 4;
for(Node n : mynodes){
int num_neig_loc = 0;
for(Node m : n.getNeighbours()){
if(m.getIsBusy()==n.getIsBusy()){
num_neig_loc++;
}
}
if(num_neig_loc<num_neigh_glob){
num_neigh_glob = num_neig_loc;
sourceNode = n;
}
}
destinationNode = freenodes.get((int) (Math.random() * freenodes.size()));
// if there is a free place beneath my token, take it
for (Node n : mynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
destinationNode = m;
}
}
}
// check for max freenodes
Node goodChoice = findMaxFreeNodes(freenodes);
if (goodChoice != null)
destinationNode = goodChoice;
for (Node n : enemynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
for(Node l : m.getNeighbours()){
if(freenodes.contains(l) && ((l.location.x == m.location.x && l.location.x == n.location.x)||(l.location.y == m.location.y && l.location.y == n.location.y))){
for(Node k : l.getNeighbours()){
if(freenodes.contains(k) && !k.getId().contains(m.getId())){
for(Node j : k.getNeighbours()){
if(enemynodes.contains(j) && ((j.location.x == k.location.x && j.location.x == l.location.x)||(j.location.y == k.location.y && j.location.y == l.location.y))){
destinationNode = l;
}
}
}
}
}
}
}
}
}
for (Node n : enemynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
for(Node k : m.getNeighbours()){
if(enemynodes.contains(k)){
destinationNode = m;
}
}
}
}
}
// check if the enemy has a mill draw
goodChoice = findMillDraw(enemynodes, freenodes);
if (goodChoice != null)
destinationNode = goodChoice;
// check if we have a mill draw
goodChoice = findMillDraw(mynodes, freenodes);
if (goodChoice != null){
destinationNode = goodChoice;
mill_created = true;
}
//System.out.println("AI: OK, I want to set " + selectedNode.getId());
game.doSomething(sourceNode.location);
game.setStones(destinationNode.location);
if(mill_created){
deleteStone(nodes,type);
}
} |
f933f993-be1a-4255-9fb6-99d8a1720f1c | public void deleteStone(Node[] nodes, int type) {
ArrayList<Node> mynodes = new ArrayList<Node>();
ArrayList<Node> enemynodes = new ArrayList<Node>();
ArrayList<Node> freenodes = new ArrayList<Node>();
Node selectedNode = null;
for (Node n : nodes) {
if (n.getIsBusy() == 0) {
freenodes.add(n);
continue;
}
if (n.getIsBusy() == type) {
mynodes.add(n);
continue;
}
enemynodes.add(n);
}
for (Node n : enemynodes) {
selectedNode = n;
for (Node m : n.getNeighbours()) {
if (m.getIsBusy() == 1) {
selectedNode = m;
break;
}
}
}
for (Node n : enemynodes) {
for (Node m : n.getNeighbours()) {
if (freenodes.contains(m)) {
for(Node l : m.getNeighbours()){
if(enemynodes.contains(l) && ((l.location.x == m.location.x && l.location.x == n.location.x)||(l.location.y == m.location.y && l.location.y == n.location.y))){
for(Node k : l.getNeighbours()){
if(freenodes.contains(k) && !k.getId().contains(m.getId())){
for(Node j : k.getNeighbours()){
if(enemynodes.contains(j) && ((j.location.x == k.location.x && j.location.x == l.location.x)||(j.location.y == k.location.y && j.location.y == l.location.y))){
selectedNode = l;
}
}
}
}
}
}
}
}
}
System.out.println("I want to delete " + selectedNode.getId());
game.doSomething(selectedNode.location);
} |
8cad7959-50c1-4095-addf-254dbfc21c1a | private Node findMaxFreeNodes(ArrayList<Node> nodes){
int maxval = 0;
Node result = null;
for(Node n : nodes){
int num = 0;
for(Node f : n.getNeighbours()){
if(f.getIsBusy() == 0){
num++;
}
}
if(num>=maxval){
maxval = num;
result = n;
}
}
return result;
} |
e3429aa0-ce65-4d16-ac11-09320daf1873 | private Node findMillDraw(ArrayList<Node> busynodes,
ArrayList<Node> freenodes) {
Node selectedNode = null;
for (Node n : busynodes) {
for (Node m : n.getNeighbours()) {
if (busynodes.contains(m)) {
for (Node f : m.getNeighbours()) {
if (freenodes.contains(f)
&& ((f.location.x == m.location.x && m.location.x == n.location.x) || (f.location.y == m.location.y && m.location.y == n.location.y))) {
selectedNode = f;
}
}
} else {
if (freenodes.contains(m)) {
for (Node f : m.getNeighbours()) {
if (busynodes.contains(f)
&& !f.equals(n)
&& ((f.location.x == m.location.x && m.location.x == n.location.x) || (f.location.y == m.location.y && m.location.y == n.location.y))) {
selectedNode = m;
}
}
}
}
}
}
return selectedNode;
} |
9da3f455-d2d7-49de-91c7-826f0e59682d | public StateOfPlay(StateOfPlay parent, Node[] nodes2copy,
Node[] originMove, int type, int level, int depth) {
this.parent = parent;
this.type = type;
this.level = level;
this.depth = depth;
if (level % 2 == 0) {
player = type;
} else {
if (type == 1) {
player = 2;
} else {
player = 1;
}
}
if (originMove != null) {
this.originMove[0] = originMove[0];
this.originMove[1] = originMove[1];
}
for (int i = 0; i < nodes2copy.length; i++) {
Node newnode = new Node(nodes2copy[i].getId(),nodes2copy[i].location.x, nodes2copy[i].location.y);
this.nodes[i] = newnode;
this.nodes[i].setIsBusy(nodes2copy[i].getIsBusy());
this.nodes[i].setUnchangedFlag(nodes2copy[i].getUnchangedFlag());
}
for (int i = 0; i < nodes2copy.length; i++){
for(Node neighbour : nodes2copy[i].getNeighbours()){
for(int j = 0; j< nodes.length ; j++){
if(nodes[j].getId().contains(neighbour.getId())){
nodes[i].addNeighbour(nodes[j]);
}
}
}
}
} |
860c1ce7-be8c-44da-8eeb-258269605324 | public void generatePossibilities() {
// System.out.println("---generating--level -" + (level+1) +
// "----------------------");
if (depth >= 0) {
for (int i = 0; i < this.nodes.length; i++) {
if (this.nodes[i].getIsBusy() == player) {
for (Node potential : this.nodes[i].getNeighbours()) {
if (potential.getIsBusy() == 0) {
for (int j = 0; j < this.nodes.length; j++) {
if (nodes[j].getId().contains(potential.getId())) {
Node[] nextmove = new Node[2];
nodes[i].setIsBusy(0);
nodes[j].setIsBusy(player);
nextmove[0] = nodes[i];
nextmove[1] = nodes[j];
Node remember = null;
if (checkNodeInMill(nodes[j], i)) {
System.out.println("I recognized the mill");
remember = findForDeletion();
analyzeNodes();
}
int turn;
if (type == 1) {
turn = 2;
} else {
turn = 1;
}
// System.out.println("---generating level "+(this.level+1)+"----");
StateOfPlay strategy = new StateOfPlay(
this, this.nodes, nextmove, type,
this.level + 1, depth - 1);
if (remember != null) {
strategy.setRememberDeletion(remember);
}
//evaluateStrategy(strategy);
this.children.add(strategy);
strategy.generatePossibilities();
if (strategy.getRememberDeletion() != null) {
System.out.println("I recognized a mill for"+ strategy.getOriginMove()[0].getId()
+ " to "
+ strategy
.getOriginMove()[1]
.getId());
if(this.type==this.player){
strategy.setValue(strategy.getValue() + (1000 / (strategy.level)));
}
else{
strategy.setValue(strategy.getValue() - (1000 / (strategy.level)));
}
remember.setIsBusy(turn);
}
nodes[i].setIsBusy(player);
nodes[j].setIsBusy(0);
}
}
}
}
}
}
} else {
StateOfPlay x = this;
while (x.level != 0) {
if (x.getPlayer() == x.getType()) {
for (StateOfPlay y : x.getChildren()) {
x.setValue(x.getValue() + y.getValue());
}
} else {
for (StateOfPlay y : x.getChildren()) {
x.setValue(x.getValue() + y.getValue());
}
}
x = x.getParent();
}
}
} |
21c83b4d-3328-43c5-b3c3-f7736b705cbc | private Node findForDeletion() {
analyzeNodes();
Node selectedNode = null;
for (Node n : enemynodes) {
selectedNode = n;
for (Node m : n.getNeighbours()) {
if (enemynodes.contains(m)) {
selectedNode = m;
break;
}
if (freenodes.contains(m)){
for(Node last : m.getNeighbours()){
if(enemynodes.contains(last) && ((last.location.x == n.location.x)||(last.location.y == n.location.y))){
selectedNode = last;
break;
}
}
}
}
}
return selectedNode;
} |
34747748-00b9-4760-aa4a-3f2060e0ddd7 | private void analyzeNodes() {
freenodes.clear();
mynodes.clear();
enemynodes.clear();
for (int i = 0; i < this.nodes.length; i++) {
if (nodes[i].getIsBusy() == 0) {
this.freenodes.add(nodes[i]);
continue;
}
if (nodes[i].getIsBusy() == player) {
this.mynodes.add(nodes[i]);
continue;
}
this.enemynodes.add(nodes[i]);
}
} |
01f4fd0b-4deb-4cca-bd26-d2197a32891f | private boolean checkNodeInMill(Node node, int p) {
System.out.println("---------------------------------");
System.out.println("we wanted to move " + nodes[p].getId() +","+nodes[p].getIsBusy()+ " to: "+node.getId() + ","+node.getIsBusy());
analyzeNodes();
for (Node n : mynodes) {
for (Node m : n.getNeighbours()) {
if (m.getIsBusy() == n.getIsBusy()
&& (m.location.x == n.location.x || m.location.y == n.location.y)) {
for (Node f : m.getNeighbours()) {
if (f.getIsBusy() == m.getIsBusy()
&& (f.location.x == m.location.x
&& (f.location.x == n.location.x) || f.location.y == m.location.y
&& (f.location.y == n.location.y))
&& !f.equals(n)){
if(n.getId().contains(node.getId()) || m.getId().contains(node.getId()) || f.getId().contains(node.getId())){
return true;
}
}
}
}
}
}
return false;
} |
bc698f6a-9a4f-4fc1-82c6-983e69a07293 | public boolean deleteSomething() {
if (rememberDeletion == null) {
return false;
} else {
return true;
}
} |
53842d8e-e762-414c-9355-b4e986967406 | public StateOfPlay calculateBestEffort() {
StateOfPlay result = null;
int maxval = this.children.get(0).getValue();
for (StateOfPlay child : this.children) {
if (child.value >= maxval) {
maxval = child.value;
result = child;
}
}
return result;
} |
89d03c9d-d817-40fb-a3c1-51a67389b590 | public Node getRememberDeletion() {
return rememberDeletion;
} |
8d335e79-ef13-44a8-9483-a1b313cde607 | public void setRememberDeletion(Node rememberDeletion) {
this.rememberDeletion = rememberDeletion;
} |
51425626-6cdf-4dc2-9de9-2bb10c2f84df | public int getType() {
return type;
} |
1bfb9c4f-7253-4ea1-b2f3-280d7566a1d8 | public int getPlayer() {
return player;
} |
95ef2a07-0455-465a-8d99-b4f165e3d4ad | public int getValue() {
return value;
} |
b95b242c-93f0-4de9-9a71-56818ee23c49 | public void setValue(int value) {
this.value = value;
} |
ffdf06ba-f7fb-4176-83a9-cf9a7a2a3f64 | public int getLevel() {
return level;
} |
9ed6f31e-aa52-4615-931e-eeccf515f3c6 | public void setLevel(int level) {
this.level = level;
} |
ec16a452-4e71-40ac-b2b2-09d543631cc6 | public StateOfPlay getParent() {
return parent;
} |
69dac0da-07ce-4ccc-93bf-83a9466acf3d | public void setParent(StateOfPlay parent) {
this.parent = parent;
} |
813924a3-4331-4612-bd3a-7c78973b218d | public ArrayList<StateOfPlay> getChildren() {
return children;
} |
9792423e-7140-4c4f-a55f-68aec1663100 | public void setChildren(ArrayList<StateOfPlay> children) {
this.children = children;
} |
80625dec-69b9-4ddf-a783-2385833706b9 | public Node[] getOriginMove() {
return originMove;
} |
240d4608-d6b7-4703-9c0a-b9f4b8f07e1e | public void setOriginMove(Node[] originMove) {
this.originMove = originMove;
} |
241fb1a9-1ee7-4063-972d-12413ee2ee47 | public Referee(NineMM game) {
this.game = game;
} |
66ddc488-543b-4f1a-9aa6-8340770232bc | public boolean checkRules(Node[] nodes, boolean isWhitesTurn) {
this.isWhitesTurn = isWhitesTurn;
boolean check = checkMill(nodes);
checkEndOfGame(nodes);
return check;
} |
0cd62106-e50d-449a-965f-e0440fe6e495 | public void checkEndOfGame(Node[] nodes) {
if(game.getPlacedCounter() < 18){
//System.out.println("Pieces placed: " + game.getPlacedCounter());
}
else{
// check for
int countblackoptions = 0;
int countwhiteoptions = 0;
for(int i = 0; i < nodes.length; i++ ){
for(Node n : nodes[i].getNeighbours()){
if(n.getIsBusy()==0){
if(nodes[i].getIsBusy()==1){
countwhiteoptions++;
}
if(nodes[i].getIsBusy()==1){
countblackoptions++;
}
}
}
}
int countBlacks = 0;
int countWhites = 0;
for(Node n : nodes){
if(n.getIsBusy() == 1){
countWhites++;
}
else{
if(n.getIsBusy() == 2){
countBlacks++;
}
}
}
if((countblackoptions == 0) || (countwhiteoptions == 0) || (countBlacks < 3) || (countWhites < 3)){
String winner = "";
if((countblackoptions == 0) || (countWhites < 3)){
winner = "Black";
}
else{
winner = "White";
}
JOptionPane.showMessageDialog(null, "End of game: " + winner + " wins the game!");
System.out.println("SPIELENDE");
}
}
} |
bf629175-61d1-4f5d-95e1-c7aa6985ec15 | private boolean checkMill(Node[] nodes) {
ArrayList<Node> whiteOccupants = new ArrayList<Node>();
ArrayList<Node> blackOccupants = new ArrayList<Node>();
int old_black_mills = 0;
int old_white_mills = 0;
for (int i = 0; i < nodes.length; i++) {
if (nodes[i].getIsBusy() == 1)
whiteOccupants.add(nodes[i]);
else if (nodes[i].getIsBusy() == 2)
blackOccupants.add(nodes[i]);
}
old_black_mills = this.blackMills.size();
old_white_mills = this.whiteMills.size();
if (isWhitesTurn) {
checkOccupants = whiteOccupants;
this.whiteMills.clear();
//System.out.println("Erased the list to:" + whiteMills.size());
} else {
checkOccupants = blackOccupants;
this.blackMills.clear();
//System.out.println("Erased the list to:" + blackMills.size());
}
// System.out.println("We used to have " + old_black_mills
// + "nodes in black mills");
// System.out.println("We used to have " + old_white_mills
// + "nodes in white mills");
for (Node n : checkOccupants) {
for (Node m : n.getNeighbours()) {
if (checkOccupants.contains(m)
&& (m.location.x == n.location.x || m.location.y == n.location.y)) {
for (Node f : m.getNeighbours()) {
if (checkOccupants.contains(f)
&& (f.location.x == m.location.x
&& (f.location.x == n.location.x) || f.location.y == m.location.y
&& (f.location.y == n.location.y))
&& !f.equals(n))
if (isWhitesTurn) {
if (!this.whiteMills.contains(n))
this.whiteMills.add(n);
if (!this.whiteMills.contains(m))
this.whiteMills.add(m);
if (!this.whiteMills.contains(f))
this.whiteMills.add(f);
} else {
if (!this.blackMills.contains(n))
this.blackMills.add(n);
if (!this.blackMills.contains(m))
this.blackMills.add(m);
if (!this.blackMills.contains(f))
this.blackMills.add(f);
}
}
}
}
}
// System.out.println("now we have " + this.blackMills.size()
// + "nodes in black mills");
//
// System.out.println("now we have " + this.whiteMills.size()
// + "nodes in white mills");
if (!isWhitesTurn && this.blackMills.size() > old_black_mills) {
System.out.println("RF: There is a black mill!!!");
return true;
}
if (isWhitesTurn && this.whiteMills.size() > old_white_mills) {
System.out.println("RF: There is a white mill!!!");
return true;
}
return false;
// if (!isWhitesTurn) {
// int whiteCheck = 0;
// for (Node n : blackMills) {
// System.out.println("in black mills: " + n.getId());
// if (n.getUnchangedFlag()) {
// whiteCheck++;
// n.setUnchangedFlag(false);
// }
// }
// if (whiteCheck > 1) {
// mill = true;
// }
// } else {
// int blackCheck = 0;
// for (Node n : whiteMills) {
// System.out.println("in white mills: " + n.getId());
// if (n.getUnchangedFlag()) {
// blackCheck++;
// n.setUnchangedFlag(false);
// }
// }
// if (blackCheck > 1) {
// mill = true;
// }
// }
// return mill;
} |
8761d233-7686-43ea-ac38-c4c88e587719 | public boolean isStart() {
return start;
} |
9481a1cd-313e-46ba-af6c-2fe7fd392719 | public void setStart(boolean start) {
this.start = start;
} |
c7316793-7dbe-4458-903a-965a159c11b2 | public String getPlayer1() {
return player1;
} |
08a47d9b-4cb4-4cf5-9809-3dbc773f87dd | public void setPlayer1(String player1) {
this.player1 = player1;
} |
b64dcbac-95a2-4396-a215-c8ba2227f0d3 | public String getPlayer2() {
return player2;
} |
c699f15c-54b0-4c21-80b2-65be1841b98e | public void setPlayer2(String player2) {
this.player2 = player2;
} |
2eb70d34-df2f-4f03-a64b-f810ab7254fb | public void printProperties() {
System.out.println("Start: " + start);
System.out.println("Player 1: " + player1);
System.out.println("Player 2: " + player2);
} |
f221d4d8-e0de-4a96-9686-e71380bbfb08 | public Splashscreen() {
setTitle("9MM - Nine Men's Morris");
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setBounds((dim.width/2-(appWidth/2)), (dim.height/2-(appHeigth/2)), appWidth, appHeigth);
contentPanel.setLayout(null);
{
JLabel lblPlayer = new JLabel("Player 1:");
lblPlayer.setBounds(23, 48, 61, 23);
contentPanel.add(lblPlayer);
}
{
JLabel lblPlayer_1 = new JLabel("Player 2:");
lblPlayer_1.setBounds(23, 90, 61, 23);
contentPanel.add(lblPlayer_1);
}
{
JLabel lblHuman = new JLabel("Human");
lblHuman.setBounds(87, 20, 50, 16);
contentPanel.add(lblHuman);
}
{
JLabel lblComputer = new JLabel("Computer");
lblComputer.setBounds(175, 20, 72, 16);
contentPanel.add(lblComputer);
}
final JRadioButton rbtn_player1_human = new JRadioButton("",true);
rbtn_player1_human.setName("Player_1_Human");
rbtn_player1_human.setBounds(96, 48, 23, 23);
contentPanel.add(rbtn_player1_human);
final JRadioButton rbtn_player2_human = new JRadioButton("",false);
rbtn_player2_human.setName("Player_2_Human");
rbtn_player2_human.setBounds(96, 90, 23, 23);
contentPanel.add(rbtn_player2_human);
final JRadioButton rbtn_player1_computer = new JRadioButton("",false);
rbtn_player1_computer.setName("Player_1_Computer");
rbtn_player1_computer.setBounds(192, 48, 23, 23);
contentPanel.add(rbtn_player1_computer);
final JRadioButton rbtn_player2_computer = new JRadioButton("",true);
rbtn_player2_computer.setName("Player_2_Computer");
rbtn_player2_computer.setBounds(192, 90, 23, 23);
contentPanel.add(rbtn_player2_computer);
ButtonGroup player1 = new ButtonGroup();
player1.add(rbtn_player1_human);
player1.add(rbtn_player1_computer);
ButtonGroup player2 = new ButtonGroup();
player2.add(rbtn_player2_computer);
player2.add(rbtn_player2_human);
final JCheckBox chckbxWannaStart = new JCheckBox("Wanna start?");
chckbxWannaStart.setSelected(true);
chckbxWannaStart.setBounds(96, 125, 128, 23);
contentPanel.add(chckbxWannaStart);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
{
JButton okButton = new JButton("OK");
setting = new Settings();
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
setting.setStart(true);
if(rbtn_player1_human.isSelected()){
setting.setPlayer1(rbtn_player1_human.getName());
}
else{
setting.setPlayer1(rbtn_player1_computer.getName());
}
if(rbtn_player2_human.isSelected()){
setting.setPlayer2(rbtn_player2_human.getName());
}
else{
setting.setPlayer2(rbtn_player2_computer.getName());
}
setting.setStart(chckbxWannaStart.isSelected());
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
NineMM window = new NineMM(setting);
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
});
okButton.setActionCommand("OK");
buttonPane.add(okButton);
getRootPane().setDefaultButton(okButton);
}
{
JButton cancelButton = new JButton("Cancel");
cancelButton.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent arg0) {
System.exit(0);
}
});
cancelButton.setActionCommand("Cancel");
buttonPane.add(cancelButton);
}
}
} |
48ba09fe-8a78-404c-bc29-93ddb618a769 | public void actionPerformed(ActionEvent arg0) {
setting.setStart(true);
if(rbtn_player1_human.isSelected()){
setting.setPlayer1(rbtn_player1_human.getName());
}
else{
setting.setPlayer1(rbtn_player1_computer.getName());
}
if(rbtn_player2_human.isSelected()){
setting.setPlayer2(rbtn_player2_human.getName());
}
else{
setting.setPlayer2(rbtn_player2_computer.getName());
}
setting.setStart(chckbxWannaStart.isSelected());
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
NineMM window = new NineMM(setting);
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
} |
b380805c-e77b-4170-a42d-ea35a0d0e68a | public void run() {
try {
NineMM window = new NineMM(setting);
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
} |
1e00b794-47e4-48f5-a9b6-4fb27e1f4223 | @Override
public void mouseClicked(MouseEvent arg0) {
System.exit(0);
} |
1fa27aeb-9307-47d0-add4-dca975e73094 | public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// NineMM window = new NineMM(null);
// window.frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
splash = new Splashscreen();
splash.setVisible(true);
} |
92170336-bb2e-4bb8-91ef-8f245118be51 | public NineMM(Settings setting) {
this.setting = setting;
splash.dispose();
initializeWindow();
initializeGameField();
} |
f0754b4c-ad6e-4cc5-a167-90ad698d33ab | private void initializeWindow() {
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
frame = new JFrame();
frame.setBounds((dim.width / 2 - (appWidth / 2)),
(dim.height / 2 - (appHeigth / 2)), appWidth, appHeigth);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
frame.setTitle("9MM - Nine Men's Morris");
leftPanel = new JPanel();
leftPanel.setForeground(new Color(0, 0, 0));
leftPanel.setBackground(new Color(255, 255, 204));
leftPanel.setBounds(6, 6, 100, 500);
frame.getContentPane().add(leftPanel);
leftPanel.setLayout(null);
JLabel lblPlayer = new JLabel("PLAYER 1");
lblPlayer.setBounds(20, 454, 61, 16);
leftPanel.add(lblPlayer);
ImageIcon texture = createImageIcon("/resources/Wood.jpg");
rightPanel = new JPanel();
rightPanel.setBackground(Color.DARK_GRAY);
rightPanel.setBounds(630, 6, 100, 500);
frame.getContentPane().add(rightPanel);
rightPanel.setLayout(null);
JLabel lblPlayer_1 = new JLabel("PLAYER 2");
lblPlayer_1.setForeground(new Color(255, 255, 255));
lblPlayer_1.setBounds(20, 454, 61, 16);
rightPanel.add(lblPlayer_1);
centerPanel = new JLayeredPane();
centerPanel.setBackground(Color.ORANGE);
centerPanel.setBounds(118, 6, 500, 500);
frame.getContentPane().add(centerPanel);
centerPanel.setLayout(null);
ImageIcon field = createImageIcon("/resources/Spielfeld_roundedCorners.png");
JLabel feld = new JLabel(field);
feld.setBounds(0, 0, 500, 500);
centerPanel.add(feld, 2);
JLabel textureCenter = new JLabel(texture);
textureCenter.setBounds(0, 0, 500, 500);
centerPanel.add(textureCenter, 3);
setupEventFields(24);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(6, 518, 724, 149);
frame.getContentPane().add(scrollPane);
txtLogArea = new JTextArea();
txtLogArea.setEditable(false);
scrollPane.setViewportView(txtLogArea);
JButton btnClose = new JButton("Close");
btnClose.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.exit(0);
}
});
btnClose.setBounds(613, 673, 117, 35);
frame.getContentPane().add(btnClose);
referee = new Referee(this);
JButton btnRestart = new JButton("Restart");
btnRestart.setBounds(487, 673, 117, 35);
frame.getContentPane().add(btnRestart);
if(turnOfStarter){
txtLogArea.append("Whites turn!\n");
}
else{
txtLogArea.append("Blacks turn!\n");
}
} |
10ab32dd-0633-4ceb-a136-e1af06a4e004 | public void actionPerformed(ActionEvent arg0) {
System.exit(0);
} |
5cfa93be-cec1-4563-879d-b19d15580dcb | private void initializeGameField() {
ImageIcon iconWhite = createImageIcon("/resources/White_Stone.png");
int space = 0;
blacks = new JLabel[9];
whites = new JLabel[9];
for (int i = 0; i < 9; i++) {
final JLabel lblWhite = new JLabel(iconWhite);
lblWhite.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// if(deleteFlag && whitesTurn){
// System.out.println("delete Stein");
// deleteFlag = false;
// lblWhite.setVisible(false);
// lblWhite.setLocation(0, 0);
// for(Point p : placedPieces){
// if(p.x == lblWhite.getBounds().x && p.y == lblWhite.getBounds().y){
// p.x = 0;
// p.y = 0;
// }
// }
// getNode(lblWhite.getBounds().getLocation()).setIsBusy(0);
//
// }
// else{
// if (placedCounter == 18) {
// if(whitesTurn){
// selectedPiece = lblWhite;
// }
// }
// }
doSomething(lblWhite.getLocation());
if(!deleteFlag){
if(setting.getPlayer1().contains("Computer")){
if(placedCounter <= 18)
brain.setStone(nodes, 1);
else{
brain.moveStone(nodes, 1);
System.out.println("seems to work");
}
}
}
}
});
lblWhite.setBounds(25, space, 50, 50);
leftPanel.add(lblWhite);
space += 35;
whites[i] = lblWhite;
}
ImageIcon iconBlack = createImageIcon("/resources/Black_Stone.png");
space = 0;
for (int i = 0; i < 9; i++) {
final JLabel lblBlack = new JLabel(iconBlack);
lblBlack.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
// if(deleteFlag && blacksTurn){
// System.out.println("delete Stein");
// deleteFlag = false;
// lblBlack.setVisible(false);
// for(Point p : placedPieces){
// if(p.x == lblBlack.getBounds().x && p.y == lblBlack.getBounds().y){
// p.x = 0;
// p.y = 0;
// }
// }
// getNode(lblBlack.getBounds().getLocation()).setIsBusy(0);
//
// }
// else{
// if (placedCounter <= 18) {
// if(blacksTurn){
// selectedPiece = lblBlack;
// }
// }
// }
doSomething(lblBlack.getLocation());
if(!deleteFlag){
if(setting.getPlayer2().contains("Computer")){
if(placedCounter <= 18)
brain.setStone(nodes, 2);
else{
brain.moveStone(nodes, 2);
System.out.println("seems to work");
}
}
}
}
});
lblBlack.setBounds(25, space, 50, 50);
rightPanel.add(lblBlack);
space += 35;
blacks[i] = lblBlack;
}
setting.printProperties();
String path = "";
if (setting.getPlayer2().contains("Computer")) {
path = "/resources/computer.png";
} else {
path = "/resources/human.png";
}
turnOfStarter = setting.isStart();
space += 64;
ImageIcon iconRight = createImageIcon(path);
JLabel lblRight = new JLabel(iconRight);
lblRight.setBounds(20, space, 64, 64);
rightPanel.add(lblRight);
if (setting.getPlayer1().contains("Computer")) {
path = "/resources/computer.png";
} else {
path = "/resources/human.png";
}
ImageIcon iconLeft = createImageIcon(path);
JLabel lblLeft = new JLabel(iconLeft);
lblLeft.setBounds(20, space, 64, 64);
leftPanel.add(lblLeft);
} |
f7d41792-662f-4aeb-b1cd-6c5b2ca20b69 | @Override
public void mouseClicked(MouseEvent e) {
// if(deleteFlag && whitesTurn){
// System.out.println("delete Stein");
// deleteFlag = false;
// lblWhite.setVisible(false);
// lblWhite.setLocation(0, 0);
// for(Point p : placedPieces){
// if(p.x == lblWhite.getBounds().x && p.y == lblWhite.getBounds().y){
// p.x = 0;
// p.y = 0;
// }
// }
// getNode(lblWhite.getBounds().getLocation()).setIsBusy(0);
//
// }
// else{
// if (placedCounter == 18) {
// if(whitesTurn){
// selectedPiece = lblWhite;
// }
// }
// }
doSomething(lblWhite.getLocation());
if(!deleteFlag){
if(setting.getPlayer1().contains("Computer")){
if(placedCounter <= 18)
brain.setStone(nodes, 1);
else{
brain.moveStone(nodes, 1);
System.out.println("seems to work");
}
}
}
} |
5982788c-0eba-4929-ae09-42caf7d36fba | @Override
public void mouseClicked(MouseEvent e) {
// if(deleteFlag && blacksTurn){
// System.out.println("delete Stein");
// deleteFlag = false;
// lblBlack.setVisible(false);
// for(Point p : placedPieces){
// if(p.x == lblBlack.getBounds().x && p.y == lblBlack.getBounds().y){
// p.x = 0;
// p.y = 0;
// }
// }
// getNode(lblBlack.getBounds().getLocation()).setIsBusy(0);
//
// }
// else{
// if (placedCounter <= 18) {
// if(blacksTurn){
// selectedPiece = lblBlack;
// }
// }
// }
doSomething(lblBlack.getLocation());
if(!deleteFlag){
if(setting.getPlayer2().contains("Computer")){
if(placedCounter <= 18)
brain.setStone(nodes, 2);
else{
brain.moveStone(nodes, 2);
System.out.println("seems to work");
}
}
}
} |
7fe15339-6a7d-44fa-9d3c-a4bc304789c8 | public void doSomething(Point point) {
if(whitesTurn){
JLabel lblWhite = getLabel(point);
if(deleteFlag && whitesTurn){
if(getNode(point).getIsBusy() == 1){
//System.out.println("delete Stein");
deleteFlag = false;
getNode(lblWhite.getBounds().getLocation()).setIsBusy(0);
lblWhite.setVisible(false);
lblWhite.setLocation(0, 0);
for(Point p : placedPieces){
if(p.x == lblWhite.getBounds().x && p.y == lblWhite.getBounds().y){
placedPieces.remove(p);
break;
}
}
if(setting.getPlayer2().contains("Computer")){
if(countPieces(false) <= 3 && placedCounter > 17){
System.out.println(countPieces(false));
brain.jumpStone(nodes, 2);
}else{
if(placedCounter > 17){
System.out.println(countPieces(false));
brain.moveStone(nodes, 2);}
}
}
}
}
else{
if (placedCounter == 18) {
if(whitesTurn){
selectedPiece = lblWhite;
}
}
}
}
else{
JLabel lblBlack = getLabel(point);
;
if(deleteFlag && blacksTurn){
if(getNode(point).getIsBusy() == 2){
System.out.println("delete Stein");
deleteFlag = false;
getNode(lblBlack.getBounds().getLocation()).setIsBusy(0);
lblBlack.setVisible(false);
for(Point p : placedPieces){
if(p.x == lblBlack.getBounds().x && p.y == lblBlack.getBounds().y){
placedPieces.remove(p);
break;
}
}
if(setting.getPlayer1().contains("Computer")){
if(countPieces(false) <= 3 && placedCounter > 17){
System.out.println(countPieces(false));
brain.jumpStone(nodes, 1);
}else{
System.out.println(countPieces(false));
brain.moveStone(nodes, 1);
}
}
}
}
else{
if (placedCounter <= 18) {
if(blacksTurn){
selectedPiece = lblBlack;
}
}
}
}
} |
d927af0f-7506-414e-ba56-d32fad25b21e | private JLabel getLabel(Point point) {
JLabel label = null;
JLabel[] searchLabel;
if(whitesTurn){
searchLabel = whites;
}
else{
searchLabel = blacks;
}
for(JLabel l : searchLabel){
if(l.getBounds().x == point.x && l.getBounds().y == point.y){
label = l;
}
}
return label;
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.