Beispiel #1
0
 //From task to Object
 public Board(BoardStruct boardStruct)
 {
     Id          = boardStruct.Id;
     ProjectName = boardStruct.ProjectName;
     ColumnsList = new List <Column>();
     foreach (var item in boardStruct.ColumnList)
     {
         ColumnsList.Add(new Column(item));
     }
     totalLimit = boardStruct.totalLimit;
 }
Beispiel #2
0
        //public void update()
        //{
        //    //BoardDAL.updateBoard(this.toStruct());
        //}

        public BoardStruct toStruct()
        {
            List <ColumnStruct> list = new List <ColumnStruct>();

            foreach (var item in this.ColumnsList)
            {
                list.Add(item.toStruct());
            }
            BoardStruct @struct = new BoardStruct(this.Id, this.ProjectName, list, this.totalLimit);

            return(@struct);
        }
        private void ExtractResponseInfo(BoardStruct response)
        {
            player = response.player;
            enemy  = response.enemy;

            foreach (Position pos in response.blocked)
            {
                if (CoordsInBounds(pos.x, pos.y))
                {
                    blocked[pos.x, pos.y] = true;
                }
            }
        }
Beispiel #4
0
/*
 * Uploads posted images upon verification
 */
        //private string[] UpLoadAllImages(string[] strImgPathArray)
        private BoardStruct UpLoadAllImages(ref BoardStruct tmpStruct)
        {
            string tmpFile;
            string thmbNailPath;
            string userDir = "";

            //get user dir
            userDir = Session["userDir"].ToString();

            //if panel is open check for loaded img files
            if (pnlAddImages.Visible)
            {
                //Collect files names, iterate through each and update accordingly
                HttpFileCollection uploadFilCol = System.Web.HttpContext.Current.Request.Files;
                int count = uploadFilCol.Count;

                //loop thru for each posted file
                for (int i = 0; i < count; i++)
                {
                    //get handle to file
                    HttpPostedFile file = uploadFilCol[i];

                    if (file.ContentLength > (int)0)
                    {
                        //get file name & ext
                        string fileName = Path.GetFileName(file.FileName);
                        string fileExt  = Path.GetExtension(file.FileName).ToLower();

                        string tmpDir = AppDomain.CurrentDomain.BaseDirectory + @"\users\" + userDir + @"\temp\";

                        //check for temp dir and create if non-existent
                        if (!(Directory.Exists(tmpDir)))
                        {
                            //'E:\kunden\homepages\31\d213027625\Showcase\users\0\0\0\0\0\0\0\1\6\2\temp\ 
                            Directory.CreateDirectory(tmpDir);
                        }

                        //get physical path to temp dir for upload
                        string path = tmpDir;

                        //Generate random file name
                        tmpFile = GenerateRandomString(8).ToLower();

                        //concatenate renamed file with ext
                        tmpFile = tmpFile + fileExt;

                        //add together path and file name; This is our fully qualified *temp path where the file gets uploaded
                        //strImgPathArray[i] = Path.Combine(path, tmpFile);
                        tmpStruct.tmpArray[i] = Path.Combine(path, tmpFile);
                        thmbNailPath          = Path.Combine(path, "thmbNail_" + tmpFile);

                        //Upload to temp dir; we'll write to perm directory after user confirms on preview!
                        //FIXME: Check for file type and size

                        if (fileName != string.Empty)
                        {
                            //resize the image and save
                            //Create an image object from the uploaded file.

                            try
                            {
                                System.Drawing.Image UploadedImage = System.Drawing.Image.FromStream(file.InputStream);
                                //Larger Image variables
                                int   maxWidth     = 400;
                                int   maxHeight    = 400;
                                int   sourceWidth  = UploadedImage.Width;
                                int   sourceHeight = UploadedImage.Height;
                                int   sourceX      = 0;
                                int   sourceY      = 0;
                                int   destX        = 0;
                                int   destY        = 0;
                                float nPercent     = 0;
                                float nPercentW    = 0;
                                float nPercentH    = 0;

                                //ThumbNail variables
                                int   maxWidth_T  = 75;
                                int   maxHeight_T = 75;
                                int   destX_T     = 0;
                                int   destY_T     = 0;
                                float nPercent_T  = 0;
                                float nPercentW_T = 0;
                                float nPercentH_T = 0;

                                //Larger Image percents
                                nPercentW = ((float)maxWidth / (float)sourceWidth);
                                nPercentH = ((float)maxHeight / (float)sourceHeight);

                                //Thumbnail percents
                                nPercentW_T = ((float)maxWidth_T / (float)sourceWidth);
                                nPercentH_T = ((float)maxHeight_T / (float)sourceHeight);

                                //Find the biggest change(smallest pct)
                                if (nPercentH < nPercentW)
                                {
                                    //Larger Image Calculations
                                    nPercent = nPercentH;
                                    destX    = System.Convert.ToInt16((maxWidth -
                                                                       (sourceWidth * nPercent)) / 2);

                                    //Thumbnail Calculations
                                    nPercent_T = nPercentH_T;
                                    destX_T    = System.Convert.ToInt16((maxWidth_T -
                                                                         (sourceWidth * nPercent_T)) / 2);
                                }
                                else
                                {
                                    //Larger Image Calculations
                                    nPercent = nPercentW;
                                    destY    = System.Convert.ToInt16((maxHeight -
                                                                       (sourceHeight * nPercent)) / 2);

                                    //ThumbNail Calculations
                                    nPercent_T = nPercentW_T;
                                    destY_T    = System.Convert.ToInt16((maxWidth_T -
                                                                         (sourceHeight * nPercent_T)) / 2);
                                }

                                //Larger Image Calculations
                                int destWidth  = (int)(sourceWidth * nPercent);
                                int destHeight = (int)(sourceHeight * nPercent);

                                //Smaller Image Calculations
                                int destWidth_T  = (int)(sourceWidth * nPercent_T);
                                int destHeight_T = (int)(sourceHeight * nPercent_T);

                                //create the larger bitmap
                                Bitmap bmPhoto = new Bitmap(maxWidth, maxHeight);
                                bmPhoto.SetResolution(UploadedImage.HorizontalResolution,
                                                      UploadedImage.VerticalResolution);

                                //create the thumbnail bitmap
                                Bitmap bmPhotoThmbNail = new Bitmap(maxWidth_T, maxHeight_T);
                                bmPhotoThmbNail.SetResolution(UploadedImage.HorizontalResolution,
                                                              UploadedImage.VerticalResolution);

                                //create larger graphic
                                Graphics grPhoto = Graphics.FromImage(bmPhoto);
                                grPhoto.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                grPhoto.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                                grPhoto.Clear(Color.Transparent);
                                grPhoto.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                                grPhoto.DrawImage(UploadedImage,
                                                  new Rectangle(destX, destY, destWidth, destHeight),
                                                  new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                                                  GraphicsUnit.Pixel);

                                //create thumbnail graphic
                                Graphics grPhotoThmbNail = Graphics.FromImage(bmPhotoThmbNail);
                                grPhotoThmbNail.SmoothingMode   = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                                grPhotoThmbNail.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                                grPhotoThmbNail.Clear(Color.Transparent);
                                grPhotoThmbNail.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                                grPhotoThmbNail.DrawImage(UploadedImage,
                                                          new Rectangle(destX_T, destY_T, destWidth_T, destHeight_T),
                                                          new Rectangle(sourceX, sourceY, sourceWidth, sourceHeight),
                                                          GraphicsUnit.Pixel);

                                //int memberID = 0;

                                //Save the Image(s)
                                // (1) "Saves" the graphic.  It really just updates the bitmap with the contents of the graphic.
                                // Basically saving it in memory.
                                // (2) Actually save the bitmap to the file system.

                                //Larger
                                grPhoto.Save();                      //  (1)
                                bmPhoto.Save(tmpStruct.tmpArray[i]); //  (2)  .., ImageFormat.Jpeg)

                                //strip out the superfluous server path and just save the file name;  this was the cause of much grief as we were saving the entire path!
                                tmpStruct.tmpArray[i] = Path.GetFileName(tmpStruct.tmpArray[i]);

                                //Thumbnail
                                grPhotoThmbNail.Save();
                                bmPhotoThmbNail.Save(thmbNailPath);

                                //Find out who is set to "change" or "add" so we know who to update
                                //  - We call the clearSelection() to let ourselves know that index has been processed
                                //TODO: append  (&& File1.Value.Length>0)
                                if (rdoImgMgr1.SelectedValue == "Change" || rdoImgMgr1.SelectedValue == "Add")
                                {
                                    tmpStruct.sItem.ImgPath1 = tmpStruct.tmpArray[i];
                                    ErrorLog.ErrorRoutine(false, "Setting1: " + tmpStruct.tmpArray[i]);
                                    rdoImgMgr1.ClearSelection();
                                }
                                else if (rdoImgMgr2.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add")
                                {
                                    tmpStruct.sItem.ImgPath2 = tmpStruct.tmpArray[i];
                                    ErrorLog.ErrorRoutine(false, "Setting2: " + tmpStruct.tmpArray[i]);
                                    rdoImgMgr2.ClearSelection();
                                }
                                else if (rdoImgMgr3.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add")
                                {
                                    tmpStruct.sItem.ImgPath3 = tmpStruct.tmpArray[i];
                                    ErrorLog.ErrorRoutine(false, "Setting3: " + tmpStruct.tmpArray[i]);
                                    rdoImgMgr3.ClearSelection();
                                }
                                else
                                {
                                    if (rdoImgMgr4.SelectedValue == "Change" || rdoImgMgr2.SelectedValue == "Add")
                                    {
                                        tmpStruct.sItem.ImgPath4 = tmpStruct.tmpArray[i];
                                        ErrorLog.ErrorRoutine(false, "Setting4: " + tmpStruct.tmpArray[i]);
                                        rdoImgMgr4.ClearSelection();
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                lblStatus.Text = "Resize/Save Error!";
                            }
                        }
                        else
                        {
                            tmpStruct.tmpArray[i] = string.Empty;
                        }
                    }
                }
            }//end main if
            //return strImgPathArray;
            return(tmpStruct);
        } //end function
Beispiel #5
0
/*
 * Things to keep in mind here for this event handler:
 *      - we process all board types here including gear
 *      - we process wanted ads too which is a very limited subset including only
 *        category, boardtype, region, town, details, and price maybe
 */

        private void imgContinue_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            //get object from session object
            classes.BoardItem tmpBoardItem = (classes.BoardItem)Session["Item"];

            //kick out if validation failed
            if (!(Page.IsValid))
            {
                return;
            }

            //array holder for pics
            string[] strImgPathArray = new string[4];

            //init img array with blank space
            for (int j = 0; j <= 3; j++)
            {
                strImgPathArray[j] = "";
            }

            //Check for new or swapped pics.  The user has 3 possible options here; Keep, delete,
            //, or change an image. ***NOTE: For BETA entry updates will not use preview_post.
            //This means pics will *not* be moved to a temp dir as we do in posting.  This should change eventually.'
            //Delete any files in imgDel array
            bool blnProcImgs = false;

            switch (rdoImgMgr1.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBoardItem.ImgPath1 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            switch (rdoImgMgr2.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBoardItem.ImgPath2 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            switch (rdoImgMgr3.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBoardItem.ImgPath3 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            switch (rdoImgMgr4.SelectedValue)
            {
            case "Keep":
                break;

            case "Delete":
                tmpBoardItem.ImgPath4 = "";
                break;

            case "Change":
                blnProcImgs = true;
                break;

            case "Add":
                blnProcImgs = true;
                break;

            default:
                break;
            }

            //Process media
            if (pnlAddImages.Visible && blnProcImgs)
            {
                //Declare and load a struct to send to UploadAllImages()
                BoardStruct bStruct = new BoardStruct();
                bStruct.sItem    = tmpBoardItem;
                bStruct.tmpArray = strImgPathArray;

                bStruct = UpLoadAllImages(ref bStruct);

                tmpBoardItem = bStruct.sItem;
            }

            //Save common data
            tmpBoardItem.Brand    = txtBrand.Text;
            tmpBoardItem.Details  = txtDetails.Text;
            tmpBoardItem.Price    = Convert.ToDecimal(txtPrice.Text);
            tmpBoardItem.IUser    = Convert.ToInt32(Session["userId"].ToString());
            tmpBoardItem.Location = (int)1;

            tmpBoardItem.AdTitle = Global.CheckString(txtAdTitle.Text);

            //Save category specific data
            switch (tmpBoardItem.Category.ToString())
            {
            case "1":     //surf

                switch (tmpBoardItem.AdType)
                {
                case 3:         //showcase
                    tmpBoardItem.GenDimensions = Global.CheckString(txtGenDims.Text);
                    tmpBoardItem.WebURL        = Global.CheckString(txtWebURL.Text.Trim());
                    break;
                }

                break;

            case "2":       //snow

                //TODO:
                //switch (tmpBoardItem.AdType)
                //{
                //    case 1: //selling
                //        break;
                //    case 2: //wanted
                //        break;
                //    case 3: //showcase
                //        break;
                //}

                break;

            case "3":       //other boards
                if (chkOther.Checked)
                {
                    tmpBoardItem.OtherBoardType = Global.CheckString(txtOtherBoard.Text);
                }
                else
                {
                    //tmpBoardItem.BoardType = Convert.ToInt32(cboBoardType.SelectedItem.Value);
                }

                tmpBoardItem.GenDimensions = Global.CheckString(txtGenDims.Text);

                //TODO:
                //switch (tmpBoardItem.AdType)
                //{
                //    case 1: //selling
                //        break;
                //    case 2: //wanted
                //        break;
                //    case 3: //showcase
                //        break;
                //}

                break;

            case "4":       //gear
                tmpBoardItem.GearItem = Global.CheckString(txtGearItem.Text);

                //TODO:
                //switch (tmpBoardItem.AdType)
                //{
                //    case 1: //selling
                //        break;
                //    case 2: //wanted
                //        break;
                //    case 3: //showcase
                //        break;
                //}

                switch (tmpBoardItem.AdType)
                {
                case 3:         //showcase
                    tmpBoardItem.GenDimensions = Global.CheckString(txtGenDims.Text);
                    tmpBoardItem.WebURL        = Global.CheckString(txtWebURL.Text.Trim());
                    break;
                }

                break;
            }

            //Save object to session variable
            Session["Item"] = tmpBoardItem;

            //Goto preview_post
            Response.Redirect("showcase_preview.aspx");
        }
Beispiel #6
0
        protected override void ExtractState(JObject jState)
        {
            BoardStruct boardStruct = SnakeJsonHandler.ParseResponseState(jState);

            currentBoard = new SnakeBoard(currentBoard, boardStruct);
        }
 public SnakeBoard(BoardStruct boardStruct)
 {
     ExtractResponseInfo(boardStruct);
 }
 public SnakeBoard(SnakeBoard board, BoardStruct boardStruct)
 {
     ExtractOldBoardInfo(board);
     ExtractResponseInfo(boardStruct);
 }
Beispiel #9
0
        private unsafe void SetupBoard(BoardStruct* b, State state, byte playerTurn)
        {
            b->Boards[0] = 0;
            b->Boards[1] = 0;
            b->Boards[2] = 0;
            b->Boards[3] = 0;
            b->Boards[4] = 0;
            b->Boards[5] = 0;
            b->Boards[6] = 0;
            b->Boards[7] = 0;
            b->Castle = 0;
            b->EnPassantTile = 0;
            b->Hash = 0;
            Board.SetPiece(b, state.PieceLocation[0], state.Pieces[0] & 0x0F, state.Pieces[0] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[1], state.Pieces[1] & 0x0F, state.Pieces[1] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[2], state.Pieces[2] & 0x0F, state.Pieces[2] & 0xF0);
            Board.SetPiece(b, state.PieceLocation[3], state.Pieces[3] & 0x0F, state.Pieces[3] & 0xF0);
            b->AttacksBlack = Board.AttackMap(b, Board.COLOR_BLACK);
            b->AttacksWhite = Board.AttackMap(b, Board.COLOR_WHITE);

            b->PlayerTurn = playerTurn;
            b->Hash = b->Hash ^ Zob.Keys[Zobrist.ZOBRIST_SIDE, b->PlayerTurn];

            Assert(b->Hash == state.Hash, "Hashes do not match");
        }
Beispiel #10
0
        /*private bool AreKingsTouching(State s)
        {
            var x1 = s.PieceLocation[0] % 8;
            var y1 = s.PieceLocation[0] >> 3;

            var x2 = s.PieceLocation[2] % 8;
            var y2 = s.PieceLocation[2] >> 3;

            return (Math.Abs(x1 - x2) <= 1 && Math.Abs(y1 - y2) <= 1);
        }*/
        /// <summary>
        /// Gets all moves that a piece can make that will RESULT IN the given position.
        /// All pieces can reverse their own move, so backwards move are the same as forwards
        /// except for pawns, they only move one way.
        /// </summary>
        /// <param name="b"></param>
        /// <param name="playerColor"></param>
        /// <returns></returns>
        private unsafe byte[][] GetMovesReverse(BoardStruct* b, byte playerColor)
        {
            var moves = new List<byte[]>();

            byte[] locations = null;

            if (playerColor == Board.COLOR_WHITE)
                locations = Bitboard.Bitboard_BitList(b->Boards[Board.BOARD_WHITE]);
            else
                locations = Bitboard.Bitboard_BitList(b->Boards[Board.BOARD_BLACK]);

            for (byte i = 0; i < locations.Length; i++)
            {
                var to = locations[i];
                var pieceMoves = Moves.GetMoves(b, to);

                // filter out all captures.. remember, this is in reverse!
                pieceMoves = pieceMoves & ~(b->Boards[Board.BOARD_WHITE] | b->Boards[Board.BOARD_BLACK]);

                var sources = Bitboard.Bitboard_BitList(pieceMoves);

                for (int j = 0; j < sources.Length; j++)
                    moves.Add(new byte[] { sources[j], to });
            }

            return moves.ToArray();
        }
Beispiel #11
0
        /// <summary>
        /// Checks for the invalid state where kings are attacking each other
        /// </summary>
        /// <param name="state"></param>
        /// <returns></returns>
        private bool AreKingsTouching(BoardStruct* b)
        {
            var whiteKing = Bitboard.ForwardBit(b->Boards[Board.BOARD_WHITE] & b->Boards[Board.BOARD_KINGS]);
            var blackKingBoard = b->Boards[Board.BOARD_BLACK] & b->Boards[Board.BOARD_KINGS];

            var attacks = Moves.GetAttacks(b, whiteKing);
            return ((blackKingBoard & attacks) > 0);
        }
Beispiel #12
0
        /// <summary>
        /// Checks a position and determines if black is mated
        /// </summary>
        /// <param name="state"></param>
        /// <param name="b"></param>
        public void CheckIfMate(State state, BoardStruct* b)
        {
            SetupBoard(b, state, Board.COLOR_BLACK);

            var from = state.PieceLocation[2];
            var moveBoard = Moves.GetMoves(b, from);
            var moves = Bitboard.Bitboard_BitList(moveBoard);

            // make sure the black king can't directly attack the white king, that's an illegal position
            if (AreKingsTouching(b))
                return;

            bool isMate = true;

            for (int j = 0; j < moves.Length; j++)
            {
                var valid = Board.Make(b, from, moves[j]);

                if (valid)
                {
                    Board.Unmake(b);
                    isMate = false;
                    break;
                }
            }

            if (isMate)
            {
                if (Board.IsChecked(b, Board.COLOR_BLACK) == 1)
                    state.DepthToMate = 0;
                else
                    state.DepthToMate = STALEMATE;
            }
        }