示例#1
0
        public void Solve()
        {

            var rootAnalysis = new PositionAnalysis
            {
                Board = Real.Board.Clone(),
            };

            AnalysesDepth.Add(rootAnalysis);
            
            // We can cheat by placing the first piece.
            var cheatPiece = Real.Pieces.Last();
            rootAnalysis.Board.PlacePiece(cheatPiece, 6, 6, 0);
            rootAnalysis.FocusX = 7;
            rootAnalysis.FocusY = 6;

            AnalyseNextPlacement(rootAnalysis);

            if (IsSolved)
            {
                //OnSolved(AnalysesDepth.Last().Board);
            }
            else
            {
                //OnFailed();
            }
        }
示例#2
0
        public JsonResult SaveAnalysisContent(JObject jsonObj)
        {
            //_logger.LogInformation("Search 开始运行");

            AjaxRtnJsonData ajaxRtnJsonData = HandlerHelper.ActionWrap(() =>
            {
                //保存备注
                string strId = jsonObj["Id"].ToString();
                string strAnalysisContent = jsonObj["AnalysisContent"].ToString();

                IFreeSql fsql = FreeSqlFactory.GetIFreeSql("rlfstock", FreeSql.DataType.Sqlite);

                PositionAnalysis source = fsql.Select <PositionAnalysis>().Where(t => t.Id == int.Parse(strId, CultureInfo.CurrentCulture)).ToOne();

                source.AnalysisContent = strAnalysisContent;

                if (source != null)
                {
                    fsql.Update <PositionAnalysis>().SetSource(source).UpdateColumns(a => a.AnalysisContent).ExecuteAffrows();
                }

                return(null);
            });

            //_logger.LogInformation("Search 结束运行");

            return(new JsonResult(ajaxRtnJsonData));
        }
示例#3
0
        public void AnalyseNextPlacement(PositionAnalysis analysis)
        {
            OnAnalysing(analysis.Board);

            analysis.NextPossiblePlacements = FindPossibleNextPlacements(analysis);
            if (!analysis.NextPossiblePlacements.Any())
            {
                OnDeadEnd(analysis.Board);
                return; // Dead end
            }
         
            foreach (var possiblePlacement in analysis.NextPossiblePlacements)
            {
                var nextAnalysis = new PositionAnalysis()
                {
                    Board = analysis.Board.Clone(),
                };
                AnalysesDepth.Add(nextAnalysis);
                {
                    nextAnalysis.Board.PlacePiece(possiblePlacement.Piece, possiblePlacement.AtX, possiblePlacement.AtY, possiblePlacement.Orientation);

                    if (!nextAnalysis.Board.UnplacedPieces.Any())
                    {
                        //IsSolved = true;
                        OnSolved(nextAnalysis.Board);
                        return;
                    }

                    FindNextFocusPoint(nextAnalysis);

                    AnalyseNextPlacement(nextAnalysis);

                    //if (IsSolved) return;
                }
                AnalysesDepth.Remove(nextAnalysis);
            }
        }
示例#4
0
        public List<PossiblePlacement> FindPossibleNextPlacements(PositionAnalysis positionAnalysis)
        {
            var list = new List<PossiblePlacement>();

            foreach (var unplacedPiece in positionAnalysis.Board.UnplacedPieces)
            for (var orientationIndex = 0; orientationIndex < 4; orientationIndex++)
            {
                var orientation = unplacedPiece.Orientations[orientationIndex];
                for (var atBoardX = positionAnalysis.FocusX - (orientation.Width - 1); atBoardX <= positionAnalysis.FocusX; atBoardX++)
                for (var atBoardY = positionAnalysis.FocusY - (orientation.Height - 1); atBoardY <= positionAnalysis.FocusY; atBoardY++)
                {
                    // Check each cell on the piece to make sure it is...
                    for (var pieceX = 0; pieceX < orientation.Width; pieceX++)
                    for (var pieceY = 0; pieceY < orientation.Height; pieceY++)
                    {
                        //... still on the board in X direction
                        var checkBoardX = atBoardX + pieceX;
                        if (checkBoardX < 0 || checkBoardX >= positionAnalysis.Board.Width) 
                            goto SkipThisLocation;

                        //... still on the board in Y direction
                        var checkBoardY = atBoardY + pieceY;
                        if (checkBoardY < 0 || checkBoardY >= positionAnalysis.Board.Height)
                            goto SkipThisLocation;

                        //...  and is the correcct outy/inny
                        if (orientation.IsOuty[pieceY, pieceX] != positionAnalysis.Board.IsOuty[checkBoardY, checkBoardX])
                            goto SkipThisLocation;

                        //... aaaaannd..... isn't overlapping an existing piece.
                        if (orientation.IsFilledIn[pieceY, pieceX] && positionAnalysis.Board.CellPieces[checkBoardY, checkBoardX] != null)
                            goto SkipThisLocation;

                        //... aaand is definitely covering the focus point
                        if (!orientation.IsFilledIn[positionAnalysis.FocusY - atBoardY, positionAnalysis.FocusX - atBoardX])
                            goto SkipThisLocation;
                    }
                     
                    // No objections to placing unplacedPiece on teh board at AtX-AtY with specified orientationIndex.
                    list.Add(new PossiblePlacement
                    {
                        AtX = atBoardX,
                        AtY = atBoardY,
                        Orientation = orientationIndex,
                        Piece = unplacedPiece,
                    });

                SkipThisLocation:
                    continue;
                }
                
            SkipThisOrientation:
                continue;
            }

            return list;
        }
示例#5
0
 public void FindNextFocusPoint(PositionAnalysis positionAnalysis)
 {
     var nextPoint = FocusPoints.First(point => positionAnalysis.Board.CellPieces[point.Y, point.X] == null);
     positionAnalysis.FocusX = nextPoint.X;
     positionAnalysis.FocusY = nextPoint.Y;
 }
示例#6
0
        public JsonResult SaveRow(JObject jsonObj)
        {
            //_logger.LogInformation("开始运行");

            AjaxRtnJsonData ajaxRtnJsonData = HandlerHelper.ActionWrap(() =>
            {
                //参数
                string Id = HandlerHelper.GetValue(jsonObj, "Id");

                string PositionStartTime = HandlerHelper.GetValue(jsonObj, "PositionStartTime");
                string PositionEndTime   = HandlerHelper.GetValue(jsonObj, "PositionEndTime");
                string CompanyCode       = HandlerHelper.GetValue(jsonObj, "CompanyCode");
                string CompanyName       = HandlerHelper.GetValue(jsonObj, "CompanyName");
                string PositionVol       = HandlerHelper.GetValue(jsonObj, "PositionVol");
                string CostPrice         = HandlerHelper.GetValue(jsonObj, "CostPrice");
                string CurrentPrice      = HandlerHelper.GetValue(jsonObj, "CurrentPrice");
                string TradeMkPlace      = HandlerHelper.GetValue(jsonObj, "TradeMkPlace");
                string Tag = HandlerHelper.GetValue(jsonObj, "Tag");

                string UserId = HandlerHelper.GetValue(jsonObj, "UserId");

                //更新/插入
                IFreeSql fsql = FreeSqlFactory.GetIFreeSql("rlfstock", FreeSql.DataType.Sqlite);

                PositionAnalysis model = null;

                if (string.IsNullOrEmpty(Id))
                {
                    model = new PositionAnalysis();
                }
                else
                {
                    model = fsql.Select <PositionAnalysis>().Where(t => t.Id == int.Parse(Id, CultureInfo.CurrentCulture)).ToOne();

                    //插入更新日志
                    if (model.Tag.IndexOf("更新日志") == -1)
                    {
                        model.Tag = "更新日志";
                        fsql.Insert <PositionAnalysis>(model).ExecuteAffrows();
                    }
                }

                //model.UserId = int.Parse(UserId);
                model.PositionStartTime = string.IsNullOrEmpty(PositionStartTime) ? (DateTime?)null : Convert.ToDateTime(PositionStartTime, CultureInfo.CurrentCulture);
                model.PositionEndTime   = string.IsNullOrEmpty(PositionEndTime) ? (DateTime?)null : Convert.ToDateTime(PositionEndTime, CultureInfo.CurrentCulture);
                model.CompanyCode       = CompanyCode;
                model.CompanyName       = CompanyName;
                model.PositionVol       = int.Parse(PositionVol, CultureInfo.CurrentCulture);
                model.CostPrice         = float.Parse(CostPrice, CultureInfo.CurrentCulture);
                model.CurrentPrice      = float.Parse(CurrentPrice, CultureInfo.CurrentCulture);
                model.TradeMkPlace      = TradeMkPlace;
                model.Tag = Tag;

                if (!string.IsNullOrEmpty(Id))
                {
                    fsql.Update <PositionAnalysis>().SetSource(model).ExecuteAffrows();
                }
                else
                {
                    if (string.IsNullOrWhiteSpace(UserId))
                    {
                        throw new BusinessException("用户Id为空!");
                    }
                    model.UserId = int.Parse(UserId);
                    fsql.Insert <PositionAnalysis>(model).ExecuteAffrows();
                }

                return(null);
            });

            //_logger.LogInformation("结束运行");

            return(new JsonResult(ajaxRtnJsonData));
        }