jagged-arrays

How can I use a jagged array to record the x and y axes of these tiles?

有些话、适合烂在心里 提交于 2020-03-25 22:01:05
问题 In the game I am making, I have a level that is created through an XML file. The level is drawn with a nested for loop. I am trying to make another nested for loop to take the position of each tile and assign it to a jagged array. I want to do this so I can make collision detection for each tile. Each tile in the picture of the example level below is 20x20 pixels, with 30x30 tiles, for a screen resolution of 600x600. The level was made with the free software Realm Factory, which lacks

Why does PowerShell flatten arrays automatically?

情到浓时终转凉″ 提交于 2020-01-14 10:39:25
问题 I've written some pwsh code "a:b;c:d;e:f".Split(";") | ForEach-Object { $_.Split(":") } # => @(a, b, c, d, e, f) but I want this // in javascript "a:b;c:d;e:f".split(";").map(str => str.split(":")) [ [ 'a', 'b' ], [ 'c', 'd' ], [ 'e', 'f' ] ] a nested array @( @(a, b), @(c, d), @(e, f), ) Why? and what should I do 回答1: Use the unary form of , , PowerShell's array-construction operator: "a:b;c:d;e:f".Split(";") | ForEach-Object { , $_.Split(":") } That way, the array returned by $_.Split(":")

How to assign to a jagged array?

旧巷老猫 提交于 2020-01-14 08:45:12
问题 I am writing a short program which will eventually play connect four. Here it is so far, pastebin There is one part which isn't working. I have a jagged array declared on line 16: char[][] board = Enumerable.Repeat(Enumerable.Repeat('-', 7).ToArray(), 7).ToArray(); Which I think looks like this: ------- ------- ------- ------- ------- ------- ------- when I do this board[5][2] = '*' I get --*---- --*---- --*---- --*---- --*---- --*---- --*---- instead of what I'd like: ------- ------- -------

How to assign to a jagged array?

China☆狼群 提交于 2020-01-14 08:45:08
问题 I am writing a short program which will eventually play connect four. Here it is so far, pastebin There is one part which isn't working. I have a jagged array declared on line 16: char[][] board = Enumerable.Repeat(Enumerable.Repeat('-', 7).ToArray(), 7).ToArray(); Which I think looks like this: ------- ------- ------- ------- ------- ------- ------- when I do this board[5][2] = '*' I get --*---- --*---- --*---- --*---- --*---- --*---- --*---- instead of what I'd like: ------- ------- -------

ASP.Net c# adding items to jagged array

依然范特西╮ 提交于 2020-01-07 06:40:33
问题 im trying to add items to jagged array's, the data is being pulled from a datarowview, i have the following code foreach (DataRowView answer in AnswersInQuestion) { answersJArray[index] = new string[noOfAnswersInQuestion]; answersJArray[index][j] = answer["ChoiceText"].ToString(); j++; } the first item gets added in fine, but when the 2nd item is put in the first item is set to null again. so for example the first time round this is what the array will look like arr[0][0] = answer 1 arr[0][1]

Save and load a jagged array

余生颓废 提交于 2020-01-07 05:05:30
问题 How can I save a jagged array in C#? For example: I have the following jagged array: double[][,] myJaggedArr=new double[2][,]; myJaggedArr[0]=new double[3,3]{{1,2,3},{4,5,6},{7,8,9}}; myJaggedArr[1]=new double[3,3]{{1,1,1},{2,2,2},{3,3,3}}; How can I save this jagged array and how can I load it? what if I have a two jagged array and I want to save it in one file? I think it is better to make a class having these two jagged arrays so I can save an object of the class. I know that I can save

How to return a jagged array

筅森魡賤 提交于 2020-01-07 02:02:17
问题 I have a function which use a 2D jagged array to save records from an SQL query. How do return the jagged array correctly? I tried something like: public string[][] GetResult() { return result; } And in my main programm: string[][] test = new string[server1.GetResult().Length][]; test = server1.GetResult(); Well, as expected, it didn't work. I don't know how to fix my problem. 回答1: Jagged arrays are simply arrays of arrays. In your code: string[][] test = new string[server1.GetResult().Length

multidimensional jagged map

て烟熏妆下的殇ゞ 提交于 2020-01-05 04:51:14
问题 I'm a c++ noob trying to build a personal finance websocket server that tracks all of my assets and liabilities in real-time. I've found that I can make map s of map s to have a multi-dimensional system of key-value pairs. I've also found that boost::any and boost::variant can be used to store multiple types for a values. My problem is that some levels aren't very complex compared to others. For example, a bank account will only have a value, the amount in the account, while a brokerage

How to delete zeros from matrix in MATLAB?

こ雲淡風輕ζ 提交于 2019-12-31 01:25:09
问题 Here is my problem: I have a nxn matrix in matlab. I want to delete all the zeros of this matrix and put the rows of it in vectors. For n=4 , let say I have the following matrix: A = [ 1 1 0 0 1 2 0 0 1 0 0 0 1 2 1 0 ]; How to get the following: v1 = [ 1 1 ]; v2 = [ 1 2 ]; v3 = [ 1 ]; v4 = [ 1 2 1 ]; I did the following: for i = 1:size(A, 1) tmp = A(i, :); tmp(A(i, :)==0)=[]; v{i} = tmp; end 回答1: Slightly faster than Divakar's answer: nzv = arrayfun(@(n) nonzeros(A(n,:)), 1:size(A,1),

set/access jagged map values made with map<string, boost::any>

时间秒杀一切 提交于 2019-12-24 19:37:57
问题 I've been shown how to create a jagged multidimensional std::map by using boost::any. However, I'm having trouble setting the values like in this answer. When I use accounts["bank"]["cash"] = 100; gcc gives this error error: no match for ‘operator[]’ in ‘accounts.std::map<_Key, _Tp, _Compare, _Alloc>::operator[]<std::basic_string<char>, boost::any, std::less<std::basic_string<char> >, std::allocator<std::pair<const std::basic_string<char>, boost::any> > >((* & std::basic_string<char>(((const