src/strategy/Parity3.java
public static Strategy classical(Game game, GameInfo gameinfo) {
		assert(game != null);
		assert(gameinfo.type == 'r');
		
		TreeMap<Integer,TreeSet<Integer>> allowed = solve(game);
		if (allowed == null) return null;
		
		// Turn the strategy into bitvector format
		
		Strategy result = new Strategy(2,'p');
		
		LinkedList<Integer> queue = new LinkedList<Integer>();
		TreeSet<Integer> flag = new TreeSet<Integer>();
		queue.add(game.initialState);
		flag.add(game.initialState);
		
		TreeMap<Integer,AtomicInteger> used = new TreeMap<Integer,AtomicInteger>();
		
		while (queue.size() > 0) {
			Integer from = queue.remove();
			if (game.states.get(from).player == 1) { // the opponent is allowed to move anywhere
				for (Integer into : game.transitions.get(from))
					if (!flag.contains(into)) {
						assert(allowed.containsKey(into));
						queue.add(into);
						flag.add(into);
					}
			} else { // restricted by the strategy
				assert(allowed.containsKey(from));
				
				int choicefrom = -1;
				int valuefrom = -1;
				int succfrom = -1;
				int choicenew = -1;
				int valuenew = -1;
				int succnew = -1;

				for (int i=0; i<Util.bitpower(game.varActionP2no()); i++) {
					int into = game.successor(gameinfo, from, i, 1);
					if (allowed.get(from).contains(into)) { // We can consider this label
						if (used.containsKey(i)) {
							if (used.get(i).intValue() > valuefrom) {
								choicefrom = i;
								valuefrom = used.get(i).intValue();
								succfrom = into;
								choicenew = -1;
								valuenew = -1;
								succnew = -1;
							}
						}
						else if (choicefrom == -1 && Util.numberOfOnes(i) > valuenew) {
								choicenew = i;
								valuenew = Util.numberOfOnes(i);
								succnew = into;
						}
					}
				}
				
				if (choicefrom != -1) {
					assert(valuefrom > -1 && succfrom > -1);
					used.get(choicefrom).incrementAndGet();
					result.addBitv(game, from, choicefrom, true);
					
					for (int i=0; i<Util.bitpower(game.varActionP2no()); i++)
						if (i != choicefrom)
							result.addBitv(game, from, i, false);
					
					if (!flag.contains(succfrom)) {
						queue.add(succfrom);
						flag.add(succfrom);							
					}
				} else {
					assert(choicenew > -1 && valuenew > -1 && succnew > -1);
					used.put(choicenew, new AtomicInteger(1));
					result.addBitv(game, from, choicenew, true);
					
					for (int i=0; i<Util.bitpower(game.varActionP2no()); i++)
						if (i != choicenew)
							result.addBitv(game, from, i, false);
					
					if (!flag.contains(succnew)) {
						queue.add(succnew);
						flag.add(succnew);
					}					
				}
				
			}
		}
				
		return result;
	}
/**
	 * Computes classical (one action per state) parity3 "min odd" strategy for player 2<br>
	 * Returns null if the initial state is not part of the winning region for player 2
	 * @param game			Compute for this game
	 * @param gameinfo		Info about the game
	 * @return				The strategy
	 */
Computes classical (one action per state) parity3 "min odd" strategy for player 2
Returns null if the initial state is not part of the winning region for player 2
@param game                  Compute for this game
@param gameinfo              Info about the game
@return                              The strategy
Computes classical ( one action per state ) parity3 " min odd " strategy for player 2 Returns null if the initial state is not part of the winning region for player 2 @param game Compute for this game @param gameinfo Info about the game @return The strategy
public static Strategy classical(Game game, GameInfo gameinfo) {
		assert(game != null);
		assert(gameinfo.type == 'r');
		TreeMap<Integer,TreeSet<Integer>> allowed = solve(game);
		if (allowed == null) return null;
		Strategy result = new Strategy(2,'p');
		LinkedList<Integer> queue = new LinkedList<Integer>();
		TreeSet<Integer> flag = new TreeSet<Integer>();
		queue.add(game.initialState);
		flag.add(game.initialState);
		TreeMap<Integer,AtomicInteger> used = new TreeMap<Integer,AtomicInteger>();
		while (queue.size() > 0) {
			Integer from = queue.remove();
			if (game.states.get(from).player == 1) { 
				for (Integer into : game.transitions.get(from))
					if (!flag.contains(into)) {
						assert(allowed.containsKey(into));
						queue.add(into);
						flag.add(into);
					}
			} else { 
				assert(allowed.containsKey(from));
				int choicefrom = -1;
				int valuefrom = -1;
				int succfrom = -1;
				int choicenew = -1;
				int valuenew = -1;
				int succnew = -1;
				for (int i=0; i<Util.bitpower(game.varActionP2no()); i++) {
					int into = game.successor(gameinfo, from, i, 1);
					if (allowed.get(from).contains(into)) { 
						if (used.containsKey(i)) {
							if (used.get(i).intValue() > valuefrom) {
								choicefrom = i;
								valuefrom = used.get(i).intValue();
								succfrom = into;
								choicenew = -1;
								valuenew = -1;
								succnew = -1;
							}
						}
						else if (choicefrom == -1 && Util.numberOfOnes(i) > valuenew) {
								choicenew = i;
								valuenew = Util.numberOfOnes(i);
								succnew = into;
						}
					}
				}
				if (choicefrom != -1) {
					assert(valuefrom > -1 && succfrom > -1);
					used.get(choicefrom).incrementAndGet();
					result.addBitv(game, from, choicefrom, true);
					for (int i=0; i<Util.bitpower(game.varActionP2no()); i++)
						if (i != choicefrom)
							result.addBitv(game, from, i, false);
					if (!flag.contains(succfrom)) {
						queue.add(succfrom);
						flag.add(succfrom);							
					}
				} else {
					assert(choicenew > -1 && valuenew > -1 && succnew > -1);
					used.put(choicenew, new AtomicInteger(1));
					result.addBitv(game, from, choicenew, true);
					for (int i=0; i<Util.bitpower(game.varActionP2no()); i++)
						if (i != choicenew)
							result.addBitv(game, from, i, false);
					if (!flag.contains(succnew)) {
						queue.add(succnew);
						flag.add(succnew);
					}					
				}
			}
		}
		return result;
	}
public static Strategy classical ( Game game , GameInfo gameinfo ) { assert ( game != null ) ; assert ( gameinfo . type == 'r' ) ; TreeMap < Integer , TreeSet < Integer > > allowed = solve ( game ) ; if ( allowed == null ) return null ; Strategy result = new Strategy ( 2 , 'p' ) ; LinkedList < Integer > queue = new LinkedList < Integer > ( ) ; TreeSet < Integer > flag = new TreeSet < Integer > ( ) ; queue . add ( game . initialState ) ; flag . add ( game . initialState ) ; TreeMap < Integer , AtomicInteger > used = new TreeMap < Integer , AtomicInteger > ( ) ; while ( queue . size ( ) > 0 ) { Integer from = queue . remove ( ) ; if ( game . states . get ( from ) . player == 1 ) { for ( Integer into : game . transitions . get ( from ) ) if ( ! flag . contains ( into ) ) { assert ( allowed . containsKey ( into ) ) ; queue . add ( into ) ; flag . add ( into ) ; } } else { assert ( allowed . containsKey ( from ) ) ; int choicefrom = - 1 ; int valuefrom = - 1 ; int succfrom = - 1 ; int choicenew = - 1 ; int valuenew = - 1 ; int succnew = - 1 ; for ( int i = 0 ; i < Util . bitpower ( game . varActionP2no ( ) ) ; i ++ ) { int into = game . successor ( gameinfo , from , i , 1 ) ; if ( allowed . get ( from ) . contains ( into ) ) { if ( used . containsKey ( i ) ) { if ( used . get ( i ) . intValue ( ) > valuefrom ) { choicefrom = i ; valuefrom = used . get ( i ) . intValue ( ) ; succfrom = into ; choicenew = - 1 ; valuenew = - 1 ; succnew = - 1 ; } } else if ( choicefrom == - 1 && Util . numberOfOnes ( i ) > valuenew ) { choicenew = i ; valuenew = Util . numberOfOnes ( i ) ; succnew = into ; } } } if ( choicefrom != - 1 ) { assert ( valuefrom > - 1 && succfrom > - 1 ) ; used . get ( choicefrom ) . incrementAndGet ( ) ; result . addBitv ( game , from , choicefrom , true ) ; for ( int i = 0 ; i < Util . bitpower ( game . varActionP2no ( ) ) ; i ++ ) if ( i != choicefrom ) result . addBitv ( game , from , i , false ) ; if ( ! flag . contains ( succfrom ) ) { queue . add ( succfrom ) ; flag . add ( succfrom ) ; } } else { assert ( choicenew > - 1 && valuenew > - 1 && succnew > - 1 ) ; used . put ( choicenew , new AtomicInteger ( 1 ) ) ; result . addBitv ( game , from , choicenew , true ) ; for ( int i = 0 ; i < Util . bitpower ( game . varActionP2no ( ) ) ; i ++ ) if ( i != choicenew ) result . addBitv ( game , from , i , false ) ; if ( ! flag . contains ( succnew ) ) { queue . add ( succnew ) ; flag . add ( succnew ) ; } } } } return result ; }
Computes classical (one action per state) parity3 "min odd" strategy for player 2<br>
 Returns null if the initial state is not part of the winning region for player 2
 @param game                  Compute for this game
 @param gameinfo              Info about the game
 @return                              The strategy
Computes classical ( one action per state ) parity3 " min odd " strategy for player 2<br > Returns null if the initial state is not part of the winning region for player 2 @param game Compute for this game @param gameinfo Info about the game @return The strategy
// Turn the strategy into bitvector format // the opponent is allowed to move anywhere // restricted by the strategy // We can consider this label