public void Initialize(string folder, int times) { _players.Clear(); _folder = folder; _times = times; if (Directory.Exists(_folder)) { string[] files = Directory.GetFiles(_folder); if (files != null) { for (int i = 0; i < files.Length; i++) { string file = files[i]; DNAPlayer player = Utility.CreateDNAPlayer(file); _players.Add(player); } } } if (_players.Count > 1) { if (_performance != null) { if (_performance.Length != _players.Count && _performance[0].Length != _players.Count) { _performance = new LeagueResult[_players.Count][]; for (int i = 0; i < _players.Count; i++) { _performance[i] = new LeagueResult[_players.Count]; for (int j = 0; j < _players.Count; j++) { _performance[i][j] = new LeagueResult(0, 0, 0); } } } else { for (int i = 0; i < _players.Count; i++) { for (int j = 0; j < _players.Count; j++) { _performance[i][j] = new LeagueResult(0, 0, 0); } } } } else { _performance = new LeagueResult[_players.Count][]; for (int i = 0; i < _players.Count; i++) { _performance[i] = new LeagueResult[_players.Count]; for (int j = 0; j < _players.Count; j++) { _performance[i][j] = new LeagueResult(0, 0, 0); } } } } }
public string StartArena(string black, string white, int rate, float min, float max) { Keys.Instance.Begin("X"); DNAPlayer blackPlayer = Utility.CreateDNAPlayer(black); DNAPlayer whitePlayer = Utility.CreateDNAPlayer(white); int performance = 0; _rule.Clear(); _rule.SetChessPlayers(blackPlayer, whitePlayer); Messager.Instance.SendMessageLater(MessageKey.Restart, new ChessPlayer[] { blackPlayer, whitePlayer }); ChessMove blackMove = StartOneChess(); if (blackMove.Side == 棋子.黑子) { performance++; } else if (blackMove.Side == 棋子.白子) { performance -= 2; } else { performance--; } _rule.Clear(); _rule.SetChessPlayers(whitePlayer, blackPlayer); Messager.Instance.SendMessageLater(MessageKey.Restart, new ChessPlayer[] { whitePlayer, blackPlayer }); ChessMove whiteMove = StartOneChess(); if (whiteMove.Side == 棋子.黑子) { performance--; } else if (whiteMove.Side == 棋子.白子) { performance += 2; } else { performance++; } Keys.Instance.End("X"); DNA blackDNA = blackPlayer.GetDNA(); DNA whiteDNA = whitePlayer.GetDNA(); string[] keys = Keys.Instance.GetAllKeys("X"); if (keys == null) { return(""); } if (performance > 0) { for (int i = 0; i < keys.Length; i++) { string key = keys[i]; if (whiteDNA.Has(key) && blackDNA.Has(key)) { whiteDNA.SetValue(key, blackDNA.GetValue(key)); } } whiteDNA.Factor = blackDNA.Factor; blackDNA.Save(); whiteDNA.Save(); return(black); } else if (performance < 0) { for (int i = 0; i < keys.Length; i++) { string key = keys[i]; if (whiteDNA.Has(key) && blackDNA.Has(key)) { blackDNA.SetValue(key, whiteDNA.GetValue(key)); } } blackDNA.Factor = whiteDNA.Factor; blackDNA.Save(); whiteDNA.Save(); return(white); } else { //Utility.Mute(blackDNA, keys, rate, min, max); //Utility.Mute(whiteDNA, keys, rate, min, max); //blackDNA.Save(); //whiteDNA.Save(); return(black); } }