static void CopyPrice(int[] cost, board[] MinBoards) { for (int i = 0; i < cost.Length; i++) { cost[i] = MinBoards[i].price; } }
public ActionResult <int> DeleteNodes([FromRoute] Int32 boardId, [FromBody] dynamic requestBody) { string authorization = Request.Headers["Authorization"]; string token = authorization.Substring("Bearer ".Length).Trim(); Int16 userId = _userService.GetUserId(token); board board = _context.board.FirstOrDefault(x => x.id == boardId && x.owner_id == userId && x.deleted_at == null); if (board == null) { throw new MindnoteException("嗚喔! 分類已經被刪除,無法瀏覽", HttpStatusCode.NotFound); } int[] nodeIds = requestBody.nodeIds.ToObject <int[]>(); List <node> nodes = _context.node.Where(x => nodeIds.Contains(x.id) && x.board_id == board.id).ToList(); foreach (node node in nodes) { node.deleted_at = DateTime.Now; node.updated_at = DateTime.Now; } return(_context.SaveChanges()); }
public ActionResult <view_node> GetNode([FromRoute] Int32 boardId, [FromRoute] Int32 nodeId) { view_node result = _contextForView.view_node.FirstOrDefault(x => x.id == nodeId && x.deleted_at == null && x.board_id == boardId); board board = _context.board.FirstOrDefault(x => x.id == boardId && x.deleted_at == null); if (board == null) { throw new MindnoteException("嗚喔! 筆記的分類已經被刪除,無法瀏覽", HttpStatusCode.NotFound); } else if (!board.is_public) { throw new MindnoteException("這個分類被作者隱藏起來了~~", HttpStatusCode.Unauthorized); } else if (result == null) { throw new MindnoteException("嗚喔! 筆記已經被刪除,無法瀏覽", HttpStatusCode.NotFound); } else { return(result); } }
public void TestMethod1() { board b = new board(); }
//Constructor public boardAnalyzer(board boardInstance, int direction) //Overridden constructor -- boardAnalyzer.directionIndex { board = boardInstance; currentDirection = direction; }
moves.AddRange(GetKingMoves(board, piecePos));
void Awake() { gb = GameObject.Find("mboard").GetComponent <board>(); }
moves.AddRange(Rook.GetRookMoves(board, piecePos));
return(GetRookMoves(board, piecePos));
return(GetBishopMoves(board, piecePos));
// Use this for initialization void Awake() { gb = GameObject.Find("mboard").GetComponent <board>(); text1 = GameObject.Find("Canvas/Text1"); }
// Use this for initialization void Start() { OGYeti.SetActive(false); LankyYeti.SetActive(false); FemaleYeti.SetActive(false); switch (YetiGameData.SelectedYeti) { case YetiGameData.YetiType.NormalYeti: OGYeti.SetActive(true); break; case YetiGameData.YetiType.LankyYeti: LankyYeti.SetActive(true); break; case YetiGameData.YetiType.FemaleYeti: FemaleYeti.SetActive(true); break; default: OGYeti.SetActive(true); break; } currentBoard = 0; currentYeti = 0; //targetTransform = startingCameraTransform; mainCamera.enabled = true; startingCamera.enabled = false; leftCamera.enabled = false; rightCamera.enabled = false; clerkCamera.enabled = false; //default board boardArray[0] = new board("Basic Board", 0, "A basic board to start you off.", snowBoard1, YetiGameData.BoardType.NormalBoard); //sideSpeed board boardArray[1] = new board("Agile Board", 50, "A board that handles well, allowing you to move side to side easier.", snowBoard2, YetiGameData.BoardType.YetiBoard); //accel board boardArray[2] = new board("Sleek Board", 100, "This board is slimmer and sleeker then the others, allowing you to reach your top speeds faster!", snowBoard3, YetiGameData.BoardType.WampBoard); //mag board boardArray[3] = new board("Magnetic Board", 300, "This board has a built in Cold Cash magnet!", snowBoard4, YetiGameData.BoardType.ATATBoard); //c val board boardArray[4] = new board("Money Board", 500, "A board with the innate ability to make Cold Cash more valuable.", snowBoard5, YetiGameData.BoardType.CashBoard); //default yeti yetiArray[0] = new yeti("OG Yeti", 0, "The original yeti.", yeti1, YetiGameData.YetiType.NormalYeti); //lanky yeti yetiArray[1] = new yeti("Lanky Yeti", 1500, "A lankier, smoother yeti.", yeti2, YetiGameData.YetiType.LankyYeti); //lanky yeti yetiArray[2] = new yeti("Female Yeti", 1500, "Yetis can be female too.", yeti3, YetiGameData.YetiType.FemaleYeti); whichView = 1; }
static void heapify(board[] arr) { int end = arr.Length - 1; //last child int start = (end - 1) / 2; //last parent while (start >= 0) { siftDown(arr, start, end); start--; } }
static void FindMinCost(board[] boards, int M, int K) { int N = boards.Length; board[] cost = new board[K]; int minCost; int totalCost = 0; int ndx; for (ndx = 0; ndx < K; ndx++) { cost[ndx] = boards[ndx]; //Get the 1st K boards cost[ndx].InHeap = true; cost[ndx].HeapIndex = ndx; totalCost += cost[ndx].price; } //Place Cost arr in Max Heap heapify(cost); //For the 1st M boards, we will have the Min Cost at the end of the loop for (; ndx < M; ndx++) { if (cost[0].price > boards[ndx].price) { cost[0].InHeap = false; //Remove from heap cost[0].HeapIndex = -1; //reset heap index to -1 totalCost -= cost[0].price; cost[0] = boards[ndx]; cost[0].InHeap = true; cost[0].HeapIndex = 0; totalCost += cost[0].price; siftDown(cost, 0, cost.Length - 1); } } int[] MinArr = new int[cost.Length]; CopyPrice(MinArr, cost); minCost = totalCost; //Iterate over each M consecutive boards int start = 0; for (; ndx < N; ndx++) { if (boards[start].InHeap) //remove element out of current window { //Remove from heap boards[start].InHeap = false; totalCost -= boards[start].price; cost[boards[start].HeapIndex] = boards[ndx]; totalCost += boards[ndx].price; cost[boards[start].HeapIndex].HeapIndex = boards[start].HeapIndex; boards[start].HeapIndex = -1; siftDown(cost, 0, cost.Length - 1); } else if (cost[0].price > boards[ndx].price) { cost[0].InHeap = false; //Replace Max Heap element with element in current window cost[0].HeapIndex = -1; totalCost -= cost[0].price; cost[0] = boards[ndx]; cost[0].InHeap = true; cost[0].HeapIndex = 0; totalCost += cost[0].price; siftDown(cost, 0, cost.Length - 1); } if (totalCost < minCost) { CopyPrice(MinArr, cost); minCost = totalCost; } start++; } Console.Write("Min cost elements: "); foreach (int i in MinArr) { Console.Write("{0} ", i); } Console.WriteLine("\nTotal min cost = {0}", minCost); }
static void siftDown(board[] arr, int start, int end) { int root = start; while ((2 * root + 1) <= end) { int child = 2 * root + 1; int swap = root; if (arr[swap].price < arr[child].price) swap = child; if ((child + 1 <= end) && (arr[swap].price < arr[child + 1].price)) swap = child + 1; if (swap != root) { board temp = arr[swap]; arr[swap] = arr[root]; arr[swap].HeapIndex = swap; arr[root] = temp; arr[root].HeapIndex = root; } else return; } }
static void Main(string[] args) { int[] price = { 7, 10, 9, 3, 10, 12, 4, 8, 6, 5 }; board[] boards = new board[price.Length]; for (int i = 0; i < price.Length; i++) { boards[i] = new board(price[i]); } FindMinCost(boards, 7, 3); Console.ReadLine(); }
// Array of all letters' list of coordinates. IList <(int x, int y)>[] charToPositionMappingArray = MapLettersFromBoardIntoArray(board: board);
base.TakeTurn(board, spot);
private void compMove() { //snapshot and worker square[8, 8] arrays board brd = new board(); Array.Copy(game.squares, brd.snapshot, game.squares.Length); Array.Copy(game.squares, brd.worker, game.squares.Length); //blank moveBoard MoveBoard[,] movboard = new MoveBoard[8, 8]; //blank panels Panel[,] pans = new Panel[8, 8]; //Piece being evaled Piece currEval = new Piece(); //dictionary that stores points that each piece has in algorithm Dictionary <Piece, int> hits = new Dictionary <Piece, int>(); //dictionary that temporarily stores the max points a Piece has, used for deciding which move a piece will make Dictionary <Piece, int> tempHits = new Dictionary <Piece, int>(); //dictionary that temporarily stores the max points a Piece has, used for deciding best move to make after initial piece move Dictionary <Piece, int> tempHits_2 = new Dictionary <Piece, int>(); //populate dictionary foreach (Piece pce in game.opponentPieces) { if (pce.alive) { hits.Add(pce, 0); tempHits.Add(pce, 0); } } //how far to look ahead, based on difficulty int limiter = 0; if (game.difficulty == "easy") { limiter = 20; } else if (game.difficulty == "medium") { limiter = 30; } else { limiter = 40; } foreach (Piece pce in game.opponentPieces) { /*Here we start by making every piece have a shot at moving first, the one that allows the best future moves, * will be selected and moved. I know it's primitive, but we're not trying to outdo HAL! */ Array.Copy(brd.snapshot, brd.worker, brd.snapshot.Length); Array.Clear(movboard, 0, movboard.Length); currEval = pce; bool isCheck = false; if (pce.alive) { //first move showValidMoves(pce, brd.worker, ref movboard, ref pans); //now cycle through each potetial move of each potential piece we could move for (int x = 0; x < 8; x++) { for (int y = 0; y < 8; y++) { if (movboard[x, y].moveable) { //now move to each movable slot move(pce, x, y, false, ref brd.worker, out isCheck); if (!isCheck) { //add points to piece since it was able to be moved, helps AI break check situation hits[pce] += 10; //now we dig deeper for (int a = 0; a < limiter; a++) { //run through pieces, the one that has most move options is chosen //________________________________________________________________ // NOTE : IN FUTURE, OPTIMIZE THIS SECTION FOR BETTER CRITERIA! foreach (Piece nextPce in game.opponentPieces) { showValidMoves(nextPce, brd.worker, ref movboard, ref pans); for (int p = 0; p < 8; p++) { for (int q = 0; q < 8; q++) { if (movboard[p, q].moveable) { if (brd.worker[p, q].name != null) { hits[pce] += 40; tempHits_2[nextPce] += 40; } hits[pce] += 10; tempHits_2[nextPce] += 10; } } } } //make move Piece holdr = new Piece(); int max = 0; foreach (KeyValuePair <Piece, int> temp in tempHits_2) { if (temp.Value > max) { holdr = temp.Key; max = temp.Value; } } //continue here, we made first move, now we found most profitable next move //finding moves that have holdr above average could be a better way of identing profitability //challenge : pick where holdr (most profitable piece moves to) foreach (Piece pice in game.opponentPieces) { if (pice.name == holdr.name) { //move most profitable second piece } } } } } } } } } }
BFS(board, visited, x, board[0].Length - 1);
}//end board class private void Form1_Load(object sender, EventArgs e) { //some issues on how click new button.. should need to create new user and password string urlstring = "http://52.24.237.185/" + newPlayer.getOperation().ToString() + "?user="******"&pass="******"Error".ToString()) { System.Diagnostics.Debug.WriteLine("Close form"); Int64[] tempboard = new Int64[64]; for (int i = 0; i < tempboard.Length; i++) { //this creates a problem as it invalid operation exception in Newtonsoft.Json.dll tempboard[i] = (Int64)jObject.Root["Board"][i]; }//end for loop board gameboard = new board(tempboard); //test printing //gameboard.printBoard(); Button[] buttons = Controls.OfType <Button>().OrderBy(b => b.TabIndex).ToArray(); int tempbutton = 0; //buttons[1].Click += (sender1, ex) => System.Console.WriteLine("button " + 1 + " pressed"); setOnClick(buttons); for (int i = 0; i < tempboard.Length; i++) { tempbutton = gameboard.getvalue(i); //cheat to create the click handlers for setOnClick() //System.Console.WriteLine("button[" + i + "].Click += (sender1, ex) => System.Console.WriteLine(\"button \" + " + i + " + \" pressed\");"); buttons[i].Text = "" + tempbutton; if (tempbutton == 1) { //it does not work while candies inside test2project, only on C drive // buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\tmp\candy1.bmp", true);//there seems to be issue with buttons as it is not working.. buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\Users\User\Desktop\candies\candies1.bmp", true); } else if (tempbutton == 2) { // buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\tmp\candy2.bmp", true);//there seems to be issue with buttons as it is not working.. buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\Users\User\Desktop\candies\candies2.bmp", true); } else if (tempbutton == 3) { // buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\tmp\candy3.bmp", true);//there seems to be issue with buttons as it is not working.. buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\Users\User\Desktop\candies\candies3.bmp", true); } else if (tempbutton == 4) { // buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\tmp\candy4.bmp", true);//there seems to be issue with buttons as it is not working.. buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\Users\User\Desktop\candies\candies4.bmp", true); } } //end for } //end json error block //added the else statement to make clear else { this.Close(); MessageBox.Show("Bad user name or password"); } }//end form 1 load method
if (IsValid(board, i, j)) {
static int Main(string[] args) { theboard = new board(); theboard.createBoard(); do { for (int y = 0; y < 3; y++) { Console.Write("|"); for (int x = 0; x < 3; x++) { if (theboard.myboard[x, y] == board.field.none) { Console.Write("_|"); } else if (theboard.myboard[x, y] == board.field.x) { Console.Write("x|"); } else if (theboard.myboard[x, y] == board.field.o) { Console.Write("o|"); } } Console.WriteLine(); } string turn = "o"; if (xTurn) { turn = "x"; } Console.WriteLine("It is " + turn + "'s Turn!"); string input; Console.WriteLine("Pls input value"); input = Console.ReadLine(); if (!input.Contains(",")) { continue; } string[] substrings = input.Split(','); List <int> i_substrings = new List <int>(); foreach (string s in substrings) { int parsedinput; if (int.TryParse(s, out parsedinput)) { i_substrings.Add(parsedinput); } else { Console.Write("not a valid number"); error = true; } } if (xTurn) { theboard.myboard[i_substrings[1], i_substrings[0]] = board.field.x; } else { theboard.myboard[i_substrings[1], i_substrings[0]] = board.field.o; } xTurn = !xTurn; }while (!error); return(0); }
// 添加网站首页的公告 public board Add([FromBody] board b) { return(repository.Add(b)); }
//main game public static void Play(playerClass p, board[] b, int f) { floor = f; clearScreen();; character = p; gameMaps = b; ConsoleKeyInfo cki; do { if (f > gameMaps.Length - 1) { WIN(); return; } board presentMap = gameMaps[f]; Console.SetCursorPosition(0, 0); presentMap.printBoard(); int[] player = presentMap.playerLocation(); int x = player[0]; int y = player[1]; if (presentMap.town) { Console.WriteLine("Where would you like to go?"); Console.Write("(G)eneral Store, (A)rmory, (O)ut of Town:"); cki = Console.ReadKey(); if (cki.Key == ConsoleKey.G) { generalStore genStore = Program.generateGeneralStore(f); genStore.enterShop(); clearScreen(); } else if (cki.Key == ConsoleKey.A) { itemShop ItemShop = Program.generateItemStore(f); ItemShop.enterShop(); clearScreen(); } else if (cki.Key == ConsoleKey.O) { f++; clearScreen(); } } else { cki = Console.ReadKey(); if (cki.Key == ConsoleKey.UpArrow) presentMap.moveUP(x, y); else if (cki.Key == ConsoleKey.DownArrow) presentMap.moveDOWN(x, y); else if (cki.Key == ConsoleKey.LeftArrow) presentMap.moveLEFT(x, y); else if (cki.Key == ConsoleKey.RightArrow) presentMap.moveRIGHT(x, y); if (presentMap.checkStairs(x, y)) { f++; clearScreen(); } if (cki.Key == ConsoleKey.Enter) { f++; clearScreen(); } } } while (cki.Key != ConsoleKey.Escape); Program.Save(character, gameMaps, f); endGame(); }
return(TryPlacePiece(board, piece, out bitmap, out x, out y));
return(GetKnightMoves(board, piecePos));
//creates gameSave public gameSave(playerClass p, board[] b, int f) { player = p; gameBoard = b; floor = f; }
}//end board class private void Form1_Load(object sender, EventArgs e) { string urlstring = "http://52.24.237.185/login?user=test&pass=test123123"; //urlstring += WebClient client = new WebClient(); Stream stream = client.OpenRead(urlstring); StreamReader reader = new StreamReader(stream); Newtonsoft.Json.Linq.JObject jObject = Newtonsoft.Json.Linq.JObject.Parse(reader.ReadLine()); // instead of WriteLine, 2 or 3 lines of code here using WebClient to download the file //i wonder if this is an issue?? System.Diagnostics.Debug.WriteLine(jObject.Root["Board"]); //stream.Close(); Int64[] tempboard = new Int64[64]; for (int i = 0; i < tempboard.Length; i++) { //this creates a problem as it invalid operation exception in Newtonsoft.Json.dll tempboard[i] = (Int64)jObject.Root["Board"][i]; }//end for loop board gameboard = new board(tempboard); //test printing gameboard.printBoard(); Button[] buttons = this.Controls.OfType <Button>().ToArray(); int tempbutton = 0; for (int i = 0; i < tempboard.Length; i++) { tempbutton = gameboard.getvalue(i); System.Console.WriteLine(tempbutton + " tempbutton " + i + " is the i"); buttons[i].Text = "" + tempbutton; if (tempbutton == 1) { //it does not work while candies inside test2project, only on C drive //buttons[i].BackgroundImage = new Bitmap(@"C:\Users\User\Desktop\candies\candies1.bmp");//button works, only with C directory instead of local C# project directory.. //BackgroundImage or Image // Set the image property. buttons[i].BackgroundImage = (Bitmap)Image.FromFile(@"C:\Users\User\Desktop\candies\candies1.bmp", true); } else if (tempbutton == 2) { buttons[i].BackgroundImage = new Bitmap(@"C:\Users\User\Desktop\candies\candies2.bmp"); } else if (tempbutton == 3) { buttons[i].BackgroundImage = new Bitmap(@"C:\Users\User\Desktop\candies\candies3.bmp"); } else if (tempbutton == 4) { buttons[i].BackgroundImage = new Bitmap(@"C:\Users\User\Desktop\candies\candies4.bmp"); } } //end for } //end form 1 load method