connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = Ice.Util.initialize(_initData); } } catch (Ice.LocalException ex) { lock (_mutex) { _destroy = true; } dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } if (_communicator.getDefaultRouter() == null) { Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(_communicator.stringToProxy(_finderStr)); try { _communicator.setDefaultRouter(finder.getRouter()); } catch (Ice.CommunicatorDestroyedException ex) { dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } catch (Exception) { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.setDefaultRouter( Ice.RouterPrxHelper.uncheckedCast(finder.ice_identity(new Ice.Identity("router", "Glacier2")))); } } try { dispatchCallbackAndWait(() => _callback.createdCommunicator(this)); RouterPrx routerPrx = RouterPrxHelper.uncheckedCast(_communicator.getDefaultRouter()); SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (Exception ex) { _communicator.destroy(); dispatchCallback(() => _callback.connectFailed(this, ex), null); } })).Start(); }
public override void connect() { IsConnecting = true; ConnectStrategy.connect(); IsTestSource = isTestSystem(); IsConnecting = false; }
connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); try { _communicator = Ice.Util.initialize(_initData); } catch (Ice.LocalException ex) { _destroy = true; new Thread( new ThreadStart(delegate() { dispatchCallback(delegate() { _callback.connectFailed(this, ex); }, null); })).Start(); return; } new Thread(new ThreadStart(delegate() { try { dispatchCallbackAndWait(delegate() { _callback.createdCommunicator(this); }); Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast( _communicator.getDefaultRouter()); Glacier2.SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (Exception ex) { try { _communicator.destroy(); } catch (Exception) { } dispatchCallback(delegate() { _callback.connectFailed(this, ex); }, null); } })).Start(); }
private BoradStatus GetBoardStatus(Model model, ChessType chessType) { BoradStatus status = BoradStatus.Nothing; ConnectStrategy connectStrategy = new ConnectStrategy(model); if (connectStrategy.IsWin(chessType)) { status = BoradStatus.Winlose; } else if (connectStrategy.IsTie()) { status = BoradStatus.Tie; } return(status); }
connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); try { _communicator = Ice.Util.initialize(_initData); } catch(Ice.LocalException ex) { _destroy = true; new Thread( new ThreadStart(() => { dispatchCallback(() => { _callback.connectFailed(this, ex); }, null); })).Start(); return; } Ice.RouterFinderPrx finder = Ice.RouterFinderPrxHelper.uncheckedCast(_communicator.stringToProxy(_finderStr)); new Thread(new ThreadStart(() => { if(_communicator.getDefaultRouter() == null) { try { _communicator.setDefaultRouter(finder.getRouter()); } catch(Ice.CommunicatorDestroyedException ex) { dispatchCallback(() => { _callback.connectFailed(this, ex); }, null); return; } catch(Exception) { // // In case of error getting router identity from RouterFinder use default identity. // Ice.Identity ident = new Ice.Identity("router", "Glacier2"); _communicator.setDefaultRouter(Ice.RouterPrxHelper.uncheckedCast(finder.ice_identity(ident))); } } try { dispatchCallbackAndWait(() => { _callback.createdCommunicator(this); }); Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast(_communicator.getDefaultRouter()); Glacier2.SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch(Exception ex) { try { _communicator.destroy(); } catch(Exception) { } dispatchCallback(() => { _callback.connectFailed(this, ex); }, null); } })).Start(); }
ConnectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator( properties: _properties, logger: _logger, observer: _observer, certificates: _certificates, caCertificates: _caCertificates, certificateValidationCallback: _certificateValidationCallback, passwordCallback: _passwordCallback); } } catch (System.Exception ex) { lock (_mutex) { _destroy = true; } _callback.ConnectFailed(this, ex); return; } if (_communicator.DefaultRouter == null) { IRouterFinderPrx?finder = null; try { finder = IRouterFinderPrx.Parse(_finderStr, _communicator); _communicator.DefaultRouter = finder.GetRouter(); } catch (CommunicatorDestroyedException ex) { _callback.ConnectFailed(this, ex); return; } catch (System.Exception ex) { if (finder == null) { _callback.ConnectFailed(this, ex); return; } else { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.DefaultRouter = finder.Clone(new Identity("router", "Glacier2"), Ice.IRouterPrx.Factory); } } } try { _callback.CreatedCommunicator(this); Ice.IRouterPrx?defaultRouter = _communicator.DefaultRouter; Debug.Assert(defaultRouter != null); var routerPrx = IRouterPrx.UncheckedCast(defaultRouter); ISessionPrx session = factory(routerPrx); Connected(routerPrx, session); } catch (System.Exception ex) { _communicator.Destroy(); _callback.ConnectFailed(this, ex); } })).Start(); }
public Judge(String name, Form1 view, Model model, RoleMgr roleMgr, ChessType chessType) : base(name, view, model, roleMgr, chessType) { ConnectStrategy = new ConnectStrategy(model); addCommand("PreviousActionCommand", isAllowPreviousActionCommand, onPreviousActionCommand); }
public DebugJudge(String name, Form1 view, Model model, RoleMgr roleMgr, ChessType chessType) : base(name, view, model, roleMgr, chessType) { ConnectStrategy = new ConnectStrategy(model); addCommand("ComputerNextCommand", isAllowComputerNextCommand, onComputerNextCommand); }
private MinMaxSearchInfo MinMaxSearch(Model pModel, ChessType chessType, bool isMaxLayer, int depth, int alpha, int beta) { MinMaxSearchCount++; int bestScore = isMaxLayer ? int.MinValue : int.MaxValue; MinMaxSearchInfo bestPosInfo = new MinMaxSearchInfo(-1, -1, bestScore); //Console.WriteLine($"depth: {depth} isMaxLayer: {isMaxLayer} MinMaxSearchCount: {MinMaxSearchCount.ToString()} alpha: {alpha.ToString()} beta: {beta}"); // y, x, score List <Tuple <int, int, int> > OrderPosScoreList = GetPossibleBestPosOrderList(pModel, chessType); foreach (Tuple <int, int, int> PosScoreTuple in OrderPosScoreList) { int y = PosScoreTuple.Item1; int x = PosScoreTuple.Item2; Model cloneModel = pModel.Clone() as Model; cloneModel.PutChessToBoard(x, y, chessType); bool isWin = false; bool isTie = false; int tmpScore = 0; Model tmpModel; //when anyone win or tie, stop search ConnectStrategy connectStrategy = new ConnectStrategy(cloneModel); isWin = connectStrategy.IsWin(chessType); isTie = connectStrategy.IsTie(); if (isWin) { Console.WriteLine($"win happen"); SearchHasResultCount++; MinMaxSearchInfo Info = new MinMaxSearchInfo(x, y, isMaxLayer ? int.MaxValue - 1 : int.MinValue + 1); Info.Model = cloneModel; return(Info); } if (depth == MinMaxSearchDepth || isTie) { SearchHasResultCount++; tmpScore = MyEvaluation.GetScore(cloneModel, MyChessType); tmpModel = cloneModel; //cloneModel.PrintBoard(); //Console.WriteLine($"y: {y} x: {x} score: {score}"); } else { ChessType nextChessType = Utility.GetOppositeChessType(chessType); MinMaxSearchInfo info = MinMaxSearch(cloneModel, nextChessType, !isMaxLayer, depth + 1, alpha, beta); //===== alpha beta pruning ===== if (isMaxLayer) { alpha = Math.Max(alpha, info.Score); } else { beta = Math.Min(beta, info.Score); } if (alpha >= beta) { return(info); } //=============================== tmpScore = info.Score; tmpModel = info.Model; } if (isMaxLayer) { if (tmpScore > bestPosInfo.Score) { bestPosInfo.Score = tmpScore; bestPosInfo.X = x; bestPosInfo.Y = y; bestPosInfo.Model = tmpModel; } } else { if (tmpScore < bestPosInfo.Score) { bestPosInfo.Score = tmpScore; bestPosInfo.X = x; bestPosInfo.Y = y; bestPosInfo.Model = tmpModel; } } if (depth == 0) { Console.WriteLine($"y: {y} x: {x} score: {tmpScore} depth: {depth} MinMaxSearchCount = {MinMaxSearchCount.ToString()}"); //bestModel.PrintBoard(); } } #region Not use find order list /* * for (int y = 0; y < GameDef.board_cell_length; y++) * { * for (int x = 0; x < GameDef.board_cell_length; x++) * { * List<List<ChessType>> board = pModel.GetBoardByCopy(); * if (board[y][x] == ChessType.None && IsPosNeedSearch(board, x, y)) * { * Model cloneModel = pModel.Clone() as Model; * cloneModel.PutChessToBoard(x, y, chessType); * * bool isWin = false; * * int score = 0; * * if (depth == MinMaxSearchDepth) * { * SearchHasResultCount++; * score = MyEvaluation.GetScore(cloneModel, MyChessType); * * //cloneModel.PrintBoard(); * //Console.WriteLine($"y: {y} x: {x} score: {score}"); * } * else * { * ConnectStrategy connectStrategy = new ConnectStrategy(cloneModel); * isWin = connectStrategy.IsWin(chessType) || connectStrategy.IsTie(); * * //when anyone win, stop search * //isWin = MyEvaluation.IsEndSearch(cloneModel, chessType); * * if (isWin) * { * score = MyEvaluation.GetScore(cloneModel, MyChessType); * } * else * { * ChessType nextChessType = Utility.GetOppositeChessType(chessType); * MinMaxSearchInfo info = MinMaxSearch(cloneModel, nextChessType, !isMaxLayer, depth + 1, alpha, beta); * * if (isMaxLayer) * alpha = Math.Max(alpha, info.Score); * else * beta = Math.Min(beta, info.Score); * * if (alpha >= beta) * return info; * * score = info.Score; * } * * } * * if (depth == 0) * { * Console.WriteLine($"y: {y} x: {x} score: {score} depth: {depth}"); * } * * if (isWin) * { * Console.WriteLine($"Win happen y: {y} x: {x} score: {score} depth: {depth}"); * } * * if (isMaxLayer) * { * if (score > bestPosInfo.Score) * { * bestPosInfo.Score = score; * bestPosInfo.X = x; * bestPosInfo.Y = y; * } * } * else * { * if (score < bestPosInfo.Score) * { * bestPosInfo.Score = score; * bestPosInfo.X = x; * bestPosInfo.Y = y; * } * } * } * } * } */ #endregion return(bestPosInfo); }
connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); try { _communicator = Ice.Util.initialize(_initData); } catch(Ice.LocalException ex) { _destroy = true; dispatchCallback(delegate() { _callback.connectFailed(this, ex); }, null); return; } new Thread(new ThreadStart(delegate() { try { dispatchCallbackAndWait(delegate() { _callback.createdCommunicator(this); }); Glacier2.RouterPrx routerPrx = Glacier2.RouterPrxHelper.uncheckedCast( _communicator.getDefaultRouter()); Glacier2.SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (Exception ex) { try { _communicator.destroy(); } catch(Exception) { } _communicator = null; dispatchCallback(delegate() { _callback.connectFailed(this, ex); }, null); } })).Start(); }
connectImpl(ConnectStrategy factory) { Debug.Assert(!_destroy); new Thread(new ThreadStart(() => { try { lock (_mutex) { _communicator = new Communicator( properties: _properties, compactIdResolver: _compactIdResolver, dispatcher: _dispatcher, logger: _logger, observer: _observer, threadStart: _threadStart, threadStop: _threadStop, typeIdNamespaces: _typeIdNamespaces); } } catch (LocalException ex) { lock (_mutex) { _destroy = true; } dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } if (_communicator.getDefaultRouter() == null) { var finder = RouterFinderPrx.Parse(_finderStr, _communicator); try { _communicator.setDefaultRouter(finder.getRouter()); } catch (CommunicatorDestroyedException ex) { dispatchCallback(() => _callback.connectFailed(this, ex), null); return; } catch (System.Exception) { // // In case of error getting router identity from RouterFinder use default identity. // _communicator.setDefaultRouter( Ice.RouterPrx.UncheckedCast(finder.Clone(new Identity("router", "Glacier2")))); } } try { dispatchCallbackAndWait(() => _callback.createdCommunicator(this)); Ice.RouterPrx?defaultRouter = _communicator.getDefaultRouter(); Debug.Assert(defaultRouter != null); RouterPrx routerPrx = RouterPrx.UncheckedCast(defaultRouter); SessionPrx session = factory(routerPrx); connected(routerPrx, session); } catch (System.Exception ex) { _communicator.destroy(); dispatchCallback(() => _callback.connectFailed(this, ex), null); } })).Start(); }