public void combinations(int[] n, GameCollection x) { int k = 3; foreach (IEnumerable <int> i in Combinations(n, k)) { x.addGame(new Game(i.ToArray()[0], i.ToArray()[1], i.ToArray()[2])); } }
public int getMove(GameCollection games, Moves pMoves, Moves cMoves, Moves av) { Random r = new Random(); Moves finalM = new Moves(); IsAvailable iA = new IsAvailable(av); /* * #################################################################### * #################################################################### * #################################################################### */ if (cMoves.getMoves().Length + pMoves.getMoves().Length == 0) // Console.WriteLine("### 000 ###"); { Moves z = games.toMoveMap(); for (int i = 0; i < 300; i++) { int mySelection = z.getMoves()[r.Next(z.getMoves().Length)]; if (iA.check(mySelection)) { Console.WriteLine("selected move: " + mySelection); return(mySelection); } if (i >= 299) { Console.WriteLine("giving up"); } } } /* * #################################################################### * #################################################################### * #################################################################### */ if (cMoves.getMoves().Length == 0 && pMoves.getMoves().Length == 1) // Console.WriteLine("### 001 ###"); { GameCollection mm = new GameCollection(); int theMove; theMove = pMoves.getMoves()[0]; Index myIdenx = games.getIndexGameContains(theMove); Console.WriteLine("index -> " + myIdenx); Console.WriteLine("games -> " + games); bool skip = false; for (int i = 0; i < games.getSize(); i++) { for (int j = 0; j < myIdenx.getSize(); j++) { if (i == myIdenx.getIndexArray()[j]) { skip = true; } } if (skip) { skip = false; continue; } mm.addGame(games.getGame(i)); } Console.WriteLine("selection -> " + mm); Moves z = mm.toMoveMap(); for (int i = 0; i < 300; i++) { int mySelection = z.getMoves()[r.Next(z.getMoves().Length)]; if (iA.check(mySelection)) { Console.WriteLine("selected move: " + mySelection); return(mySelection); } if (i >= 299) { Console.WriteLine("giving up"); } } } /* * #################################################################### * #################################################################### * #################################################################### */ if (cMoves.getMoves().Length + pMoves.getMoves().Length >= 3) // Console.WriteLine("### 002 ###"); { Gen lol = new Gen(); GameCollection p = new GameCollection(); GameCollection c = new GameCollection(); GameCollection playerSelection = new GameCollection(); GameCollection computerSelection = new GameCollection(); lol.combinations(pMoves.getMoves(), p); lol.combinations(cMoves.getMoves(), c); Console.WriteLine("player combination: " + p); Console.WriteLine("computer combination: " + c); // combinacoes prontas, pesquisar jogos for (int i = 0; i < p.getSize(); i++) { int myIdenx = games.getIndexGameContains(p.getGame(i).getGameArray()[0], p.getGame(i).getGameArray()[1]); if (myIdenx != -1) { playerSelection.addGame(games.getGame(myIdenx)); } } for (int i = 0; i < c.getSize(); i++) { int myIdenx = games.getIndexGameContains(c.getGame(i).getGameArray()[0], c.getGame(i).getGameArray()[1]); if (myIdenx != -1) { computerSelection.addGame(games.getGame(myIdenx)); } } Console.WriteLine("playerSelection = " + playerSelection); Console.WriteLine("computerSelection = " + computerSelection); Console.WriteLine("playerSelection.toMoveArray = " + playerSelection.toMoveArray()); Console.WriteLine("computerSelection.toMoveArray = " + computerSelection.toMoveArray()); if (computerSelection.getSize() > 0) { for (int i = 0; i < computerSelection.toMoveArray().getMoves().Length; i++) { int mySelection = computerSelection.toMoveArray().getMoves()[i]; Console.WriteLine("computer iA.check -> " + iA.check(mySelection)); Console.WriteLine("mySelection -> " + mySelection); if (iA.check(mySelection)) { return(mySelection); } } } if (playerSelection.getSize() > 0) { for (int i = 0; i < playerSelection.toMoveArray().getMoves().Length; i++) { int mySelection = playerSelection.toMoveArray().getMoves()[i]; Console.WriteLine("player iA.check -> " + iA.check(mySelection)); Console.WriteLine("mySelection -> " + mySelection); if (iA.check(mySelection)) { return(mySelection); } } } else { Console.WriteLine("foideus"); } /* * for (int i = 0; i < computerSelection.toMoveArray().getMoves().Length; i++) * { * int mySelection = computerSelection.toMoveArray().getMoves()[i]; * if (iA.check(mySelection)) * { * return mySelection; * } * } */ } Console.WriteLine("tudo errado."); /* * #################################################################### * #################################################################### * #################################################################### */ if (true) // last resort { GameCollection mm = new GameCollection(); int theMove; theMove = cMoves.getMoves()[0]; Index myIdenx = games.getIndexGameContains(theMove); Console.WriteLine("index -> " + myIdenx); Console.WriteLine("games -> " + games); for (int i = 0; i < games.getSize(); i++) { for (int j = 0; j < myIdenx.getSize(); j++) { if (i == myIdenx.getIndexArray()[j]) { mm.addGame(games.getGame(i)); } } } Console.WriteLine("selection -> " + mm); Moves z = mm.toMoveMap(); for (int i = 0; i < 300; i++) { int mySelection = z.getMoves()[r.Next(z.getMoves().Length)]; if (iA.check(mySelection)) { Console.WriteLine("selected move: " + mySelection); return(mySelection); } if (i >= 299) { Console.WriteLine("giving up"); } } } // real last resort if (true) { GameCollection mm = new GameCollection(); Console.WriteLine("Last Resort"); Console.WriteLine("Available moves -> " + av); Console.WriteLine("Games -> " + games); Console.WriteLine("cMoves -> " + cMoves); Console.WriteLine("pMoves -> " + pMoves); GameCollection gaminhoLastResourt = new GameCollection(); GameCollection pGames = new GameCollection(); for (int i = 0; i < cMoves.getMoves().Length; i++) { Index holyDog = games.getIndexGameContains(cMoves.getMoves()[i]); for (int j = 0; j < holyDog.getIndexArray().Length; j++) { gaminhoLastResourt.addGame(games.getGame(holyDog.getIndexArray()[j])); } } Console.WriteLine("gaminho -> " + gaminhoLastResourt.toMoveArray()); if (gaminhoLastResourt.getSize() > 0) { for (int i = 0; i < gaminhoLastResourt.toMoveArray().getMoves().Length; i++) { int mySelection = gaminhoLastResourt.toMoveArray().getMoves()[i]; Console.WriteLine("player iA.check -> " + iA.check(mySelection)); Console.WriteLine("mySelection -> " + mySelection); if (iA.check(mySelection)) { return(mySelection); } } } else { Console.WriteLine("foideus de novo, #semata"); } } return(-1); }