Kontakt

Fakturační údaje

IČ: 87189224, BÚ: 1958653063/0800

Contact info in QR code

Siege (Obkličovačka)

Informace

Stáhni a hraj!

  • Spustitelný soubor hry si stáhnou oba hráči
  • Zakladatel hry
    • V nabídce "Game > Create" vytvoří novou hru
    • Pošle protihráči svou IP adresu (zjistí ji v levém dolním rohu okna)
  • Protihráč
    • Jakmile obdrží IP adresu zakladatele hry, v nabídce "Game > Join" se připojí ke hře
  • Cílem je zabrat co nejvíce soupeřových polí.
  • Pozn.: Síťové spojení funguje na LAN (lokální) síťi a na počítačích s veřejnou IP adresou.

Zdrojové kódy (zip)

Zdrojové kódy (prohlížení)

  1: package siege.core;
  2: 
  3: import java.util.Collection;
  4: import java.util.HashSet;
  5: import java.util.LinkedList;
  6: 
  7: /**
  8:  * Detect territory within specified area
  9:  * @author Ondrej Macoszek, ondra@macoszek.cz
 10:  */
 11: public class TerritoryDetector
 12: {
 13:     private Playboard playboard;
 14:     private PlayboardPoint startPoint;
 15:     private Territory foundTerritory;
 16:     private LinkedList<Crossroad> unexplored;
 17: 
 18:     public TerritoryDetector(Playboard playboard)
 19:     {
 20:         super();
 21:         this.playboard = playboard;
 22:     }
 23: 
 24:     public void setStartPoint(PlayboardPoint startPoint)
 25:     {
 26:         if(startPoint.hasOwner() == false) {
 27:             throw new IllegalArgumentException("Starting point in territory detector must have set owner");
 28:         }
 29:         this.startPoint = startPoint;
 30:     }
 31: 
 32:     public PlayboardPoint getStartPoint()
 33:     {
 34:         return startPoint;
 35:     }
 36: 
 37:     public void search()
 38:     {
 39:         // add starting point to unexplored directions
 40:         unexplored = new LinkedList<Crossroad>();
 41:         HashSet<Territory> territories = new HashSet<Territory>();
 42:         HashSet<PlayboardPoint> exploredPoints = new HashSet<PlayboardPoint>();
 43: 
 44:         Path firstPath = new Path();
 45:         firstPath.add(startPoint);
 46:         unexplored.add(new Crossroad(firstPath, startPoint));
 47: 
 48:         // uninterruptedPath
 49:         Path uninterruptedPath = null;
 50: 
 51:         // reset previous found territory
 52:         foundTerritory = null;
 53: 
 54:         // exploring unexplored crossroads
 55:         exploringCrossroads:
 56:         while(unexplored.isEmpty() == false) {
 57:             Crossroad crossroad = unexplored.pollLast();
 58: 
 59:             // get surrounding points
 60:             LinkedList<PlayboardPoint> surroundingPoints = new LinkedList<PlayboardPoint>();
 61:             Player player = crossroad.direction.getOwner();
 62:             PlayboardPoint exploredPoint = crossroad.direction;
 63: 
 64:             if(exploredPoints.contains(exploredPoint)) {
 65:                 continue;
 66:             } else {
 67:                 exploredPoints.add(exploredPoint);
 68:             }
 69: 
 70:             // search for surrounding points
 71:             surroundingPointsSearch:
 72:             for (int y = -1; y <= 1; y++) {
 73:                 for (int x = -1; x <= 1; x++) {
 74:                     // skip currently explorated point
 75:                     if(y == 0 && x == 0) {
 76:                         continue;
 77:                     }
 78: 
 79:                     // if computed coordinate is valid within playboard
 80:                     if(playboard.isValidCoord(exploredPoint.getX()+x, exploredPoint.getY()+y)) {
 81:                         PlayboardPoint point = playboard.getPoint(exploredPoint.getX()+x, exploredPoint.getY()+y);
 82: 
 83:                         // must not belong to different player
 84:                         if(point.hasOwner(player) == false) {
 85:                             continue;
 86:                         }
 87: 
 88:                         // must not be the inner point
 89:                         if(point.hasParentTerritory(PointStatus.INNER)) {
 90:                             continue;
 91:                         }
 92: 
 93:                         // must not be part of current path
 94:                         if(crossroad.path.contains(point)) {
 95:                             // if found point is starting point
 96:                             if(point.equals(startPoint) && crossroad.path.size()>2) {
 97:                                 uninterruptedPath = crossroad.path;
 98:                                 territories.add(new Territory(uninterruptedPath));
 99:                                 //break exploringCrossroads;
100:                                 continue;
101:                             } else {
102:                                 continue;
103:                             }
104:                         }
105: 
106:                         // is valid surrounding point now
107:                         surroundingPoints.add(point);
108:                     }                    
109:                 }
110:             } // end of surroundingPointsSearch
111: 
112:             // create crossroads from surrounding points
113:             if(surroundingPoints.size() == 1) {
114:                 // found single surrounding point
115:                 PlayboardPoint point = surroundingPoints.getFirst();
116:                 // add found point to current path
117:                 crossroad.path.add(point);
118:                 // set found point as new explore direction
119:                 crossroad.direction = point;
120:                 // add to queue (will explore modified crossroad again)
121:                 unexplored.add(crossroad);
122:             } else if(surroundingPoints.size() > 1) {
123:                 // found multiple surrounding points
124:                 for (PlayboardPoint point : surroundingPoints) {
125:                     Path currentPath = new Path(crossroad.path);
126:                     currentPath.add(point);
127:                     // add to queue (will explore new crossroad)
128:                     unexplored.add(new Crossroad(currentPath, point));
129:                 }
130:             }
131: 
132:         } // end of exploringCrossroads
133: 
134: 
135:         for (Territory territory : territories) {
136:             if(foundTerritory == null) {
137:                 foundTerritory = territory;
138:                 continue;
139:             }
140:             if(territory.getArea() > foundTerritory.getArea()) {
141:                 foundTerritory = territory;
142:             }
143:         }
144: 
145:     }
146: 
147:     public Territory getFoundTerritory()
148:     {
149:         return foundTerritory;
150:     }
151: 
152:     public class Crossroad
153:     {
154:         public Path path;
155:         public PlayboardPoint direction;
156: 
157:         public Crossroad(Path path, PlayboardPoint direction)
158:         {
159:             this.path = path;
160:             this.direction = direction;
161:         }
162:     }
163: 
164:     public class Path extends LinkedList<PlayboardPoint>
165:     {
166:         public Path()
167:         {
168:             super();
169:         }
170: 
171:         public Path(Collection<PlayboardPoint> path)
172:         {
173:             super(path);
174:         }
175:     }
176: 
177: }
178: