public void TestSEECaptureBad2() { string fen = @"1k1q4/8/2p5/3b3R/8/5Q2/8/2R3K1 w - - 0 1"; var bb = Chess.Base.Notation.ReadFEN(fen); var b = Helpers.ManagedBoardToNative(bb); var result = SEE.Capture(b, 21, 35); Assert.AreEqual(330 - 900, result); }
public void TestSEESquarePinned() { string fen = @"2kq4/8/2p5/3b3R/8/4N3/8/2R3K1 w KQkq - 0 1"; var bb = Chess.Base.Notation.ReadFEN(fen); var b = Helpers.ManagedBoardToNative(bb); var result = SEE.Square(b, 35); Assert.AreEqual(330, result); }
public override bool Deactivate() { if (in_click) { ((IActiveView)ext.FocusMap).Refresh(); return base.Deactivate(); } SEEUserInterfaceUtils.removeSEELayer(featureClass, ext); this.featureClass = null; this.see = null; //app.CurrentTool = null; return base.Deactivate(); }
private void updateData() { spectrum.reflashEnergy(); LLA = position.getPosition(); spectrum.calFlux(LLA[2], LLA[0], LLA[1]); //由于总剂量效应需要输入未经屏蔽的电子能谱,所以先于shield计算 totalDose.calRadiation(spectrum.getProtonEnergy(), spectrum.getProtonFlux(), shield); SEE.shield(shield, getProtonEnergy(), getProtonFlux(), SEE.ProtonLET); SEE.shield(shield, getElectronEnergy(), getElectronFlux(), SEE.ElectronLET); calculateRadiation(); }
public void update(Transaction current, SEE see) { IFeatureClass fc = null; try { fc = osdb.OpenFeatureClass(OSDB_SEE_NAME); } catch(Exception e) { MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT", "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new HandledException(e); } IFeatureCursor fcrs = null; IQueryFilter filter = null; try { filter = new QueryFilterClass(); filter.WhereClause = SEE_ID_COL + " = " + current.TxId; fcrs = fc.Update(filter,false); IFeature buffer = fcrs.NextFeature(); if(buffer == null) { Logger.Write("Transaction not found"); return; } // load it up buffer.set_Value(fcrs.FindField(PGDB_PATH_COL),current.PGDB.FullName); IPolygon p = see.Shape; if(p!=null) { p = (IPolygon)((IClone)p).Clone(); p.Project(((IGeoDataset)fc).SpatialReference); } buffer.Shape = p; fcrs.UpdateFeature(buffer); } finally { if (filter != null) { Utils.Release(filter); } if(fcrs != null) { Utils.Release(fcrs); } } }
public void insert(Transaction current, SEE see, ISpatialReference utmSR) { // Create table on datastore PGDB first? current.TxId = see.RestID; IPolygon sourcePolygon = see.Shape; //sourcePolygon.Project(utmSR); IFields fields = new FieldsClass(); IFieldsEdit fieldsEdit = (IFieldsEdit)fields; fieldsEdit.FieldCount_2 = 3; //Create the Object ID field. IField fieldUserDefined = new Field(); IFieldEdit fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "OBJECTID"; fieldEdit.AliasName_2 = "OBJECT ID"; fieldEdit.Type_2 = esriFieldType.esriFieldTypeOID; fieldsEdit.set_Field(0, fieldUserDefined); // Create the Shape field. fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; // Set up the geometry definition for the Shape field. IGeometryDef geometryDef = new GeometryDefClass(); IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef; geometryDefEdit.GeometryType_2 = ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon; // By setting the grid size to 0, you're allowing ArcGIS to determine the appropriate grid sizes for the feature class. // If in a personal geodatabase, the grid size will be 1000. If in a file or ArcSDE geodatabase, the grid size // will be based on the initial loading or inserting of features. geometryDefEdit.GridCount_2 = 1; geometryDefEdit.set_GridSize(0, 0); geometryDefEdit.HasM_2 = false; geometryDefEdit.HasZ_2 = false; //Assign the spatial reference that was passed in, possibly from //IGeodatabase.SpatialReference for the containing feature dataset. if (see.Shape.SpatialReference != null) { geometryDefEdit.SpatialReference_2 = see.Shape.SpatialReference; } //if (utmSR == null) //{ // ISpatialReferenceFactory2 sre = (ISpatialReferenceFactory2)new SpatialReferenceEnvironment(); // utmSR = sre.CreateSpatialReference((int)esriSRProjCSType.esriSRProjCS_NAD1983UTM_10N); //} //geometryDefEdit.SpatialReference_2 = utmSR;// see.Shape.SpatialReference; // Set standard field properties. fieldEdit.Name_2 = "SHAPE"; fieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry; fieldEdit.GeometryDef_2 = geometryDef; fieldEdit.IsNullable_2 = true; fieldEdit.Required_2 = true; fieldsEdit.set_Field(1, fieldUserDefined); // Create a field of type double to hold some information for the features. fieldUserDefined = new Field(); fieldEdit = (IFieldEdit)fieldUserDefined; fieldEdit.Name_2 = "SPATIAL_EDIT_EXTENT_SP_ID"; fieldEdit.AliasName_2 = "SPATIAL_EDIT_EXTENT_SP_ID"; fieldEdit.Editable_2 = true; fieldEdit.IsNullable_2 = false; fieldEdit.Length_2 = 125; fieldEdit.Type_2 = esriFieldType.esriFieldTypeString; fieldsEdit.set_Field(2, fieldUserDefined); // Create a feature class description object to use for specifying the CLSID and EXTCLSID. IFeatureClassDescription fcDesc = new FeatureClassDescriptionClass(); IObjectClassDescription ocDesc = (IObjectClassDescription)fcDesc; ESRI.ArcGIS.esriSystem.UID CLSID = new ESRI.ArcGIS.esriSystem.UIDClass(); // The enumFieldError enumerator can be inspected at this point to determine // which fields were modified during validation. IFeatureClass fc = osdb.CreateFeatureClass(OSDB_SEE_NAME, fields, ocDesc.InstanceCLSID, ocDesc.ClassExtensionCLSID, esriFeatureType.esriFTSimple, fcDesc.ShapeFieldName, ""); //IGeoDatasetSchemaEdit fd_ed = (IGeoDatasetSchemaEdit)fc; //ISpatialReference oldSR = ((IGeoDataset)fc).SpatialReference; //if (fd_ed.CanAlterSpatialReference && !oldSR.Equals(utmSR)) //{ // // does not reproject the data // // doees alter all child feature classes // fd_ed.AlterSpatialReference(utmSR); //} IWorkspaceEdit wse = (IWorkspaceEdit)osdb; wse.StartEditing(false); wse.StartEditOperation(); try { fc = osdb.OpenFeatureClass(OSDB_SEE_NAME); } catch(Exception e) { MessageBox.Show("OSDB Feature Class " + OSDB_SEE_NAME + " Not Found in SUITT", "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); throw new HandledException(e); } IFeatureCursor fcrs = null; try { fcrs = fc.Insert(false); IFeatureBuffer buffer = fc.CreateFeatureBuffer(); buffer.set_Value(fcrs.FindField(SEE_ID_COL), RestTransactionManager.Instance.NewTransactionSeeID); //buffer.set_Value(fcrs.FindField(OSDB_NAME_COL),current.OperationalDatasetName); //string t = current.Description; //if (t != null && t.Length > EDIT_INTENT_COL_LNG) //{ // t = t.Substring(0, EDIT_INTENT_COL_LNG); //} //buffer.set_Value(fcrs.FindField(EDIT_INTENT_COL), t); //buffer.set_Value(fcrs.FindField(OPEN_DATE_COL),current.CreationDate); //t = current.PGDB.FullName; //buffer.set_Value(fcrs.FindField(PGDB_PATH_COL), t); IPolygon p = sourcePolygon; if(p!=null) { //p.Project(utmSR); p.Project(((IGeoDataset)fc).SpatialReference); } buffer.Shape = p; fcrs.InsertFeature(buffer); fcrs.Flush(); // Explicitly release the cursor. Marshal.ReleaseComObject(fcrs); // Stop editing. wse.StopEditOperation(); wse.StopEditing(true); } catch(Exception e) { // Failed while writing the SEE area poygon to the PGDB? // We should carry on with the transaction, but the SEE area will be lost MessageBox.Show("Error occured storing SEE geometry. " + e.Message); } finally { if(fcrs != null) { Utils.Release(fcrs); } } }
// returns a List of all pseudo-legal ChessMoves for a given player public static List <ChessMove> GenerateMoves(int player, bool unquietOnly) { // initialize moves List List <ChessMove> moves = new List <ChessMove>(0); UInt64 currentPiece = 0, targetBitBoard = 0, tempMove = 0; GameState state = AI.states[AI.states.Count - 1]; uint piece = ChessBoard.EMPTY; // iterate through piece BitBoards and generate moves if (player == ChessBoard.WHITE) // white to move { // set targetBitBoard to squares white can move to if (!unquietOnly) { targetBitBoard = AI.board.empty_squares | AI.board.black_pieces; } else if (unquietOnly) { targetBitBoard = AI.board.black_pieces; } //--------------------// // WHITE PAWNS // //--------------------// // set piece and currentPiece BitBoard currentPiece = AI.board.white_pawn; piece = ChessBoard.W_PAWN; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = ChessBoard.PAWN_ADVANCES[fromSq] & AI.board.empty_squares; // if generating only unquiet moves, set target bit board to only promoting squares if (unquietOnly) { tempMove &= 0xFF00000000000000; } else { // check for double push if (GetRank(fromSq) == 1 && tempMove != 0) { tempMove |= ((ChessBoard.PAWN_ADVANCES[fromSq] << 8) & AI.board.empty_squares); } } // add capture moves tempMove |= ChessBoard.PAWN_CAPTURES[fromSq] & AI.board.black_pieces; // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // if promotion is possible, add all possible promotion moves; else add default move if (GetRank(toSq) == 7) { moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.W_QUEEN)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.W_ROOK)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.W_BISHOP)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.W_KNIGHT)); } else { moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // check for en passant capture if (state.enPassant != -1) { if ((ChessBoard.PAWN_CAPTURES[fromSq] & ChessBoard.SQUARES[state.enPassant]) != 0) { moves.Add(new ChessMove(fromSq, (uint)state.enPassant, piece, ChessBoard.B_PAWN, ChessBoard.W_PAWN)); } } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // WHITE KNIGHTS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.W_KNIGHT; currentPiece = AI.board.white_knight; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetKnightMoves(fromSq, targetBitBoard); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // WHITE BISHOPS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.W_BISHOP; currentPiece = AI.board.white_bishop; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetBishopMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // WHITE ROOKS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.W_ROOK; currentPiece = AI.board.white_rook; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetRookMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // WHITE QUEENS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.W_QUEEN; currentPiece = AI.board.white_queen; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetQueenMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // WHITE KING // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.W_KING; currentPiece = AI.board.white_king; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetKingMoves(fromSq, targetBitBoard); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // if not generating only unquiet moves, check for castling moves if (!unquietOnly) { // check for 0-0 (king's side castling) if (state.wCanCastle00 && (ChessBoard.FG_MASK & AI.board.occupied_squares) == 0) { if (!IsAttacked(ChessBoard.EG_MASK, ChessBoard.BLACK)) { moves.Add(new ChessMove(4, 6, piece, ChessBoard.EMPTY, ChessBoard.W_KING)); } } // check for 0-0-0 (queen's side castling) if (state.wCanCastle000 && (ChessBoard.BD_MASK & AI.board.occupied_squares) == 0) { if (!IsAttacked(ChessBoard.CE_MASK, ChessBoard.BLACK)) { moves.Add(new ChessMove(4, 2, piece, ChessBoard.EMPTY, ChessBoard.W_KING)); } } } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } } else if (player == ChessBoard.BLACK) // black to move { // set targetBitBoard to squares black can move to if (unquietOnly) { targetBitBoard = AI.board.white_pieces; } else if (!unquietOnly) { targetBitBoard = AI.board.empty_squares | AI.board.white_pieces; } //--------------------// // BLACK PAWNS // //--------------------// // set currentPiece BitBoard currentPiece = AI.board.black_pawn; piece = ChessBoard.B_PAWN; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // add standard moves tempMove = (ChessBoard.PAWN_ADVANCES[fromSq] >> 16) & AI.board.empty_squares; // if generating only unquiet moves, set target bit board to only promoting squares if (unquietOnly) { tempMove &= 0x00000000000000FF; } else { // check for double push if (GetRank(fromSq) == 6 && tempMove != 0) { tempMove |= ((ChessBoard.PAWN_ADVANCES[fromSq] >> 24) & AI.board.empty_squares); } } // add capture moves tempMove |= (ChessBoard.PAWN_CAPTURES[fromSq] >> 16) & AI.board.white_pieces; // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // if promotion is possible, generate all possible promotion moves if (GetRank(toSq) == 0) { moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.B_QUEEN)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.B_ROOK)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.B_BISHOP)); moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.B_KNIGHT)); } else { moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // check for en passant capture if (state.enPassant != -1) { if (((ChessBoard.PAWN_CAPTURES[fromSq] >> 16) & ChessBoard.SQUARES[state.enPassant]) != 0) { moves.Add(new ChessMove(fromSq, (uint)state.enPassant, piece, ChessBoard.W_PAWN, ChessBoard.B_PAWN)); } } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // BLACK KNIGHTS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.B_KNIGHT; currentPiece = AI.board.black_knight; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetKnightMoves(fromSq, targetBitBoard); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // BLACK BISHOPS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.B_BISHOP; currentPiece = AI.board.black_bishop; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetBishopMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // BLACK ROOKS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.B_ROOK; currentPiece = AI.board.black_rook; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetRookMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // BLACK QUEENS // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.B_QUEEN; currentPiece = AI.board.black_queen; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetQueenMoves(fromSq, targetBitBoard, AI.board.occupied_squares); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } //--------------------// // BLACK KING // //--------------------// // set piece and currentPiece BitBoard piece = ChessBoard.B_KING; currentPiece = AI.board.black_king; // loop until all pieces have been checked while (currentPiece != 0) { // get origin square uint fromSq = GetNextSquare(currentPiece); // create standard moves BitBoard tempMove = GetKingMoves(fromSq, targetBitBoard); // loop until all destinations for currentPiece have been checked while (tempMove != 0) { // get destination square uint toSq = GetNextSquare(tempMove); // get capture piece type uint capt = AI.board.theBoard[toSq]; // add move moves.Add(new ChessMove(fromSq, toSq, piece, capt, ChessBoard.EMPTY)); // if move is a capturing move, run standing pat evaluation if (capt != 0) { SEE.EvaluateCapture(ref moves, player); } // remove toSq from tempMove BitBoard tempMove ^= ChessBoard.SQUARES[toSq]; } // if not generating only unquiet moves, check for castling moves if (!unquietOnly) { // check for 0-0 (king's side castling) if (state.bCanCastle00 && (ChessBoard.FG_MASK & AI.board.occupied_squares) == 0) { if (!IsAttacked(ChessBoard.EG_MASK, ChessBoard.WHITE)) { moves.Add(new ChessMove(60, 62, piece, ChessBoard.EMPTY, ChessBoard.B_KING)); } } // check for 0-0-0 (queen's side castling) if (state.bCanCastle000 && (ChessBoard.BD_MASK & AI.board.occupied_squares) == 0) { if (!IsAttacked(ChessBoard.CE_MASK, ChessBoard.WHITE)) { moves.Add(new ChessMove(60, 58, piece, ChessBoard.EMPTY, ChessBoard.B_KING)); } } } // remove fromSq from currentPiece BitBoard currentPiece ^= ChessBoard.SQUARES[fromSq]; } } // return moves List return(moves); }
public override void OnMouseDown( int button, int shift, int x, int y ) { try { IPolygon pPoly; IGraphicsContainer pGraCont; IRubberBand pRubberPoly; // QI for the IGraphicsContainerSelect interface on the document's activeview pGraCont = (IGraphicsContainer)ext.FocusMap; // Create a new RubberPolygon pRubberPoly = new RubberPolygon(); // Check which mouse button was pressed... if (1 == button) { // If button 1 (left) then create a new polygon (TrackNew) // Return a new Polygon from the tracker object using TrackNew pPoly = (IPolygon)pRubberPoly.TrackNew(((IActiveView)pGraCont).ScreenDisplay, null); if (pPoly != null) { pPoly.SpatialReference = this.ext.FocusMap.SpatialReference; if (see == null) { see = new SEE(); } see.Expand(pPoly, this.ext); SEEUserInterfaceUtils.updateAcetate(see, featureClass, ext); if (SEEUserInterfaceUtils.isUserDone()) { var geometryCollection = see.Shape as IGeometryCollection; bool isMulti = geometryCollection != null && geometryCollection.GeometryCount > 1; if (isMulti) { MessageBox.Show("Multipolygons cannot be processed with SUITT at this time. Please ensure your SEE Area of Interest is a single polygon feature."); } else finishTransaction(); } } } // Refresh the activeview ((IActiveView)ext.FocusMap).Refresh(); } catch (CancelException ex) { Logger.Write("User Canceled SEE Operation: " + ex.Message + Environment.NewLine + ex.StackTrace); // cancelled in_click = false; this.endHourGlass(); app.CurrentTool = null; } catch (HandledException he) { Logger.Write(he); in_click = false; this.endHourGlass(); app.CurrentTool = null; } catch (Exception e) { MessageBox.Show(e.Message + " : " + e.StackTrace, "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); in_click = false; if (this.ext.TransactionManager.Current() != null) { try { this.ext.TransactionManager.Close(); } catch (Exception ex) { // ignored System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); //ajw: added } } this.endHourGlass(); } finally { app.CurrentTool = null; } }
private SEE initSEELayer() { // add / clear SEE acetate layer if (featureClass != null) { SEEUserInterfaceUtils.removeSEELayer(featureClass,ext); } featureClass = SEEUserInterfaceUtils.setupSEELayer(ext); // load SEE from selected set IPolygon p = this.ext.TransactionManager.Current().get_SEE(); SEE see = null; // create SEE from selected set see = SEEUserInterfaceUtils.generateFromSelected(ext,featureClass); if(p!=null && !p.IsEmpty) { if(see == null) { see = new SEE(); } see.Expand(p,this.ext); } SEEUserInterfaceUtils.updateAcetate(see, featureClass, ext); return see; }
private void checkUTM(SEE see) { int newutm = see.calculate_UTM_Zone(); if(this.ext.TransactionManager.Current().UTM != newutm){ DialogResult dr = MessageBox.Show("Previously calculated UTM Zone is no longer accurate.\n Do you wish to continue?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (dr == DialogResult.No) { throw new CancelException("UTM Rejected"); } } }
protected override void handleClick() { if (in_click) return; this.featureClass = null; this.see = null; Logger.Write("Handle New Click Event"); in_click = true; // create SEE startHourGlass("Generating initial shape"); try { see = initSEELayer(); } finally { endHourGlass(); } // expand see try { bool see_in_progress = false; if (see.isEmpty()) { MessageBox.Show("The Spatial Editing Extent is empty.\n Please draw the initial bounds for this transaction", "SEE Definition", MessageBoxButtons.OK, MessageBoxIcon.Information); see_in_progress = true; } else { // prompt user see_in_progress = !SEEUserInterfaceUtils.isUserDone(); var geometryCollection = see.Shape as IGeometryCollection; bool isMulti = geometryCollection != null && geometryCollection.GeometryCount > 1; if (isMulti) { MessageBox.Show("Multipolygons cannot be processed with SUITT at this time. Please ensure your SEE Area of Interest is a single polygon feature."); see_in_progress = true; } } if (see_in_progress) { // activate this object as the current tool // this will activate the event handlers below Logger.Write("Activating 'new' tool"); UID uid = new UIDClass(); uid.Value = "{" + CmdExpand.GUID + "}"; IDocument doc = app.Document; app.CurrentTool = doc.CommandBars.Find(uid, false, false); //Utils.Release(doc); } else { // do the main work here finishTransaction(); } in_click = false; this.endHourGlass(); } catch (CancelException ex) { Logger.Write("User Canceled SEE Operation: " + ex.Message + Environment.NewLine + ex.StackTrace); // cancelled in_click = false; this.endHourGlass(); app.CurrentTool = null; } catch (HandledException he) { Logger.Write(he); in_click = false; this.endHourGlass(); app.CurrentTool = null; } catch (Exception e) { Logger.Warn(e); MessageBox.Show("An Unexpected Error Occured: " + e.Message + "\n\tPlease Review the Log.", "EXCEPTION", MessageBoxButtons.OK, MessageBoxIcon.Error); in_click = false; if (this.ext.TransactionManager.Current() != null) { try { this.ext.TransactionManager.Close(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message + "\n" + ex.StackTrace); //ajw: added // ignore } } this.endHourGlass(); app.CurrentTool = null; } Logger.Write("End New Click Event"); }
public static void updateAcetate(SEE see, IFeatureClass featureClass, ISDUTExtension ext) { if(see == null) { return; } Logger.Write("Update acetate"); IFeature feat = null; if(featureClass.FeatureCount(null) < 1) { feat = featureClass.CreateFeature(); feat.Shape = see.Shape; feat.Store(); } else { feat = featureClass.Update(null,false).NextFeature(); feat.Shape = see.Shape; feat.Store(); } Logger.Write("Update acetate -- Refresh"); ((IActiveView)ext.FocusMap).Refresh(); }
public static SEE generateFromSelected(ISDUTExtension ext, IFeatureClass target) { Logger.Write("Create See based on selection"); IMap map = ext.FocusMap; IEnumFeature selection = (IEnumFeature)map.FeatureSelection; ((IEnumFeatureSetup)selection).AllFields = true; ((IEnumFeatureSetup)selection).Recycling = false; int i=0; ArrayList t = new ArrayList(); IGeometry shape = null; for(IFeature feat = selection.Next();feat!=null;feat = selection.Next()) { if(i > UNION_SET_OPT && shape != null) { t.Add(((IClone)shape).Clone()); shape = null; i = 0; } if(feat.Shape!= null && esriGeometryType.esriGeometryPolygon.Equals(feat.Shape.GeometryType)) { IGeometry g = feat.ShapeCopy; if (g != null && (g.SpatialReference == null || g.SpatialReference is IUnknownCoordinateSystem)) { g.SpatialReference = ext.FocusMap.SpatialReference; } if (!g.SpatialReference.Equals(((IGeoDataset)target).SpatialReference)) { g.Project(((IGeoDataset)target).SpatialReference); } if(shape == null) { if (g != null) { IEnvelope env = new EnvelopeClass(); g.QueryEnvelope(env); double buf = (Math.Max(env.Width,env.Height)) * (ext.TransactionManager.getShapeAlterPercentage()/100.0); ((IPolycurve)g).Weed(buf); } shape = g; } else { shape = merge(shape, g,ext); } i++; } } if(shape!=null) t.Add(((IClone)shape).Clone()); while(t.Count > 1) { t = merge(t,ext); } SEE see = new SEE(); if(t.Count>0) { see.Expand((IPolygon)t[0],ext); } Logger.Write("See from selection is "+see); return see; }