void generate(PApplet pa) { int space = World.space; // sz^3 pisteitä, joiden välillä space tyhjää (tyhjä 0: kuutio) // eli (sz + (sz - 1) * space) ^ 3 tileä // visited ~ V_new wikipedian algossa boolean[] visited = new boolean[size3]; int[] visitorder = new int[size3]; // indeksoidaan järjestysnumerolla // aluksi size on pisteiden määrä, newsize sitten kun niiden väliin on venytetty kulkuväyliä int newsz = size + (size - 1) * space; int newsz3 = newsz * newsz * newsz; map = new int[newsz3]; // lähtöpaikka visitorder[0] = 0; visited[0] = true; map[0] = 0xffffffff; // käydään kaikki alkuperäiset pisteet läpi, jokaiseen mennään jotenkin for (int count = 1; count < size3; count++) { // - arvo tiili reunalta // (randomilla saattaa tulla sellainenkin joka ei ole reunalla, ei väliä kun ei jättikarttoja) // vois tietty pitää listaa sellaisista joista ei vielä pääse kaikkialle... // - arvo sille suunta // - visitoi se. int vidx; do { vidx = (int) (pa.random(0, count)); // monesko jo visitoitu leviää. } while (full(visited, visitorder[vidx])); int idx = visitorder[vidx]; int z = idx / (size * size), y = idx / size % size, x = idx % size; // joku vierestä, dir on akselin suuntainen yksikkövektori int[] dir = getadj(pa, x, y, z, visited); int nx = x + dir[0], ny = y + dir[1], nz = z + dir[2]; int newidx = world.at(nx, ny, nz); visitorder[count] = newidx; visited[newidx] = true; // nykykohta venytetyssä maailmassa int i = x * (space + 1), j = y * (space + 1), k = z * (space + 1); // nurkkien välillä debugväreillä for (int a = 0; a < space; a++) { i += dir[0]; j += dir[1]; k += dir[2]; // vihreä kasvaa iteraatioiden kasvaessa, sininen taas z:n mukaan map[world.at(i, j, k, newsz)] = pa.color(1, (int) ((float) count / size3 * 255), (int) ((float) k / newsz * 255)); } // verkon kärkipisteet punaisia map[world.at(i + dir[0], j + dir[1], k + dir[2], newsz)] = pa.color(255, 0, 0); } world.size = newsz; world.size3 = newsz3; world.map = map; }
/** * TODO deprecate strings in favour of certificates XXX currently we only support a single player * per connection. * * @param player the player trying to connect * @return true if the connection was successfully identified with the specified player */ public synchronized boolean addConnection(ConnectionToServer c, Player player, byte[] signature) { logger.log(Level.INFO, "Authenticating player " + player.getName()); /* determine whether this identity already exists */ NonNullElements i = new NonNullElements(KEY.PLAYERS, serverGameEngine.getWorld(), Player.AUTHORITATIVE); while (i.next()) { Player p = (Player) i.getElement(); if (p.getName().equals(player.getName())) { /* this player already exists */ /* is this identity already connected ? */ if (principals.containsValue(p)) { logger.log(Level.INFO, "Player " + p.getName() + " is already" + " connected"); return false; } /* is this player the same as the one which previously * connected under the same name? */ logger.log(Level.FINE, "Verifying player " + p + " with " + player); if (!p.verify(player, signature)) { logger.log(Level.WARNING, "Couldn't verify signature of player " + p.getName()); return false; } principals.put(c, p); /* set the connection world */ if (c instanceof LocalConnection) { // don't create a WorldView, since the local client needs // to synchronize against the world object itself. c.setWorld(serverGameEngine.getWorld()); } else { c.setWorld(new WorldView(serverGameEngine.getWorld(), p.getPrincipal())); } return true; } } /* this player does not already exist */ logger.log( Level.INFO, "Adding player " + player.getName() + " to " + serverGameEngine.getWorld()); MoveConfirmer mc = new MoveConfirmer(serverGameEngine.getMoveExecuter(), serverGameEngine.getMoveChainFork()); AddPlayerMove m = new AddPlayerMove(serverGameEngine.getWorld(), player); MoveStatus ms = mc.confirmMove(m, null); assert ms == MoveStatus.MOVE_OK; /* * get the newly created player-with-principal */ World w = serverGameEngine.getWorld(); assert (w != null); player = (Player) w.get(KEY.PLAYERS, w.size(KEY.PLAYERS, Player.AUTHORITATIVE) - 1, Player.AUTHORITATIVE); principals.put(c, player); /* Perform any moves necessary for adding a new player */ serverGameEngine .getMoveExecuter() .processMove(statGatherer.generateNewPlayerMove(player.getPrincipal()), c); serverGameEngine .getMoveExecuter() .processMove(scenario.getSetupMoves(serverGameEngine.getWorld(), player.getPrincipal()), c); /* set the connection world */ c.setWorld(new WorldView(serverGameEngine.getWorld(), player.getPrincipal())); return true; }