public int[] SetStep(Map m, Token.PlayerColor color, int[] p, int check, Control contrl, List<int[]> taken) { int[] pos = ChooseToken(m, color, taken); int[,] help; if (m.Field[pos[0], pos[1]].Tok == "stone"){ Token.PlayerColor c = m.Field[pos[0], pos[1]].Color; help = new Stone(c).nextStep(m, pos);//field of information where you can move, or have to move a stone } else{ Token.PlayerColor c = m.Field[pos[0], pos[1]].Color; help = new Draught(c).nextStep(m, pos);//field of information where you can move, or have to move a draught } return new int[]{-1,-1}; }
public World(int priority, int size, Draught.Control control, Map map) : base(priority) { this.control = control; this.map = map; map.addListener(this); tokens = new Token[size, size]; board = new Board3D(boardBase, size); atMouse = Token.empty; atMousePos[0] = -1; atMousePos[1] = -1; this.refresh(); }
//returns the field the Player wants to visit public int[] SetStep(Map m, Token.PlayerColor color, int[] pos, int check, Control contrl, List<int[]> taken) { int[,] help; Random r = new Random(); int r1; List<int[]> priority = new List<int[]>(); List<int[]> visitable = new List<int[]>(); if (m.Field[pos[0], pos[1]].Tok == "stone") { Token.PlayerColor c = m.Field[pos[0], pos[1]].Color; help = new Stone(c).nextStep(m, pos);//field of information where you can move, or have to move a stone } else { Token.PlayerColor c = m.Field[pos[0], pos[1]].Color; help = new Draught(c).nextStep(m, pos);//field of information where you can move, or have to move a draught } for (int a = 0; a < help.GetLength(1); ++a) { for (int b = 0; b < help.GetLength(1); ++b) { if (help[a, b] == 1) priority.Add(new int[] { a, b }); //builds a list of field with priority if (help[a, b] == 0) visitable.Add(new int[] { a, b });//builds a list of field which are visitable } } int[] temp; Token[,] field = m.Field; if (priority.Count != 0) {//if there are fields with higher priority for(int i=0; i<priority.Count; i++) { temp = new int[] { priority[i][0], priority[i][1] }; contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] }; return temp; } } else { for(int i=0; i<visitable.Count; i++) { temp = new int[] { visitable[i][0], visitable[i][1] }; if (!removeTokens(field, color, temp, m)) { contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] }; return temp; } } } if (check < 80) { taken.Add(pos); return SetStep(m, color, ChooseToken(m, color, taken), check + 1, contrl, taken); } else { if (priority.Count != 0) {//if there are fields with higher priority r1 = r.Next(0, priority.Count); temp = new int[] { priority[r1][0], priority[r1][1] };//choose a random field } else { r1 = r.Next(0, visitable.Count); temp = new int[] { visitable[r1][0], visitable[r1][1] };//choose a random field } contrl.temp = new int[] { pos[0], pos[1], temp[0], temp[1] }; return temp; } }
internal void startGame(int size, Draught.Intelligence p1, Draught.Intelligence p2) { map = new Map(size); control = new Draught.Control(map, p1, p2, this); world = new World(1, size, control, map); world.setVisible(true); drawManager.addDrawable(world); f.registerMouseListener(world); guiManager.closeActiveGui(); }
// Methode zum ausfuehren genehmigter Spielzuege public void doTurn(int[] posN, int[] posO, Token t, bool beaten) { l.getGuiManager().setInGameLableText(""); // Pruefe zunaechst, in welche Richtung die Figur bewegt werden soll int[] direct = new int[2]; if (posN[0] < posO[0]) { direct[0] = -1; if (posN[1] < posO[1]) //TopLeft direct[1] = -1; else //TopRight direct[1] = 1; } else { direct[0] = 1; if (posN[1] < posO[1]) //BottomLeft direct[1] = -1; else //BottomRight direct[1] = 1; } int diff = Math.Abs(posN[0]-posO[0])+1; // Gehe mit Hilfe der Richtung den diagonalen Weg zum Zielfeld und entferne ggf. dort stehende Steine List<int[]> removeList = new List<int[]>(); for (int i = 1; i < diff; i++) { removeList.Add(new int[]{posO[0]+(i*direct[0]), posO[1]+(i*direct[1])}); } // Fuehre die eigentliche Bewegung in der Map aus removeList.Add(posO); // Importiere die moeglichen naechsten Schritte zur Ueberpruefung, ob das Spiel fortgesetzt werden kann // Wenn letzte Reihe, dann wird Stein zur Dame bool draught = false; if (((!isBlack(act) && posN[1] == 0) || (isBlack(act) && posN[1] == m.Field.GetLength(0)-1)) && t.Tok=="stone") { draught = true; Draught d = new Draught(t.Color); removeList.Add(posN); m.AddToken(posN, d); t = d; //Naechste Schritte der Dame sind andere als eines Steins } m.RemoveToken(removeList); m.AddToken(posN, t); int[,] possNext = t.nextStep(m, posN); if (beaten) temp = null; if (beaten&&!draught) { for (int i = 0; i < possNext.GetLength(0); i++) { for (int j = 0; j < possNext.GetLength(1); j++) { if (possNext[i, j] == 1) { if (!isHuman(act)) { AINext(posN); } return; } } } } // Weiter zum naechsten Spieler act = changeIndex(); // Wenn naechster Spieler keine Figuren oder moegliche zuege mehr hat, dann ist das Spiel beendet. if (!hasStones(act)||!hasTurns(act,false)) { msg = true; wait = true; return; } if (!isHuman(act)) AINext(null); else { if (act.Color == Intelligence.eColor.white) { errorMessage("Spieler 2 ist am Zug!", false); } else { errorMessage("Spieler 1 ist am Zug!", false); } } // BEI AI WARTE AUF AUFRUF VON AI_NEXT(), sonst warte auf Aufruf von checkTurn bei Klick von Benutzer }