#code-talk
2 messages ยท Page 10 of 1
so you're talking about the RX/TX pins?
what model arduino do you have
ah okay, so your serial port connects pins 0 (RX) and 1 (TX)
yes
I am going to need a custom cable to start xD
I am wondering though, if serial communication is just a standard c library or something with just a bunch of functions to send through a connected cable
I am totally clueless on this subject
Oh I see, you have both USART and UART for the avr
but thats the avr side
so from what I understand you need to enable the optional interface (uart0) in this case through the config on the device?
I think you're going to need to set a flag on one of the arduino's registers yes. but I am not that far yet
The USART has to be initialized before any communication can take place. The initialization process normally consists of setting the baud rate, setting frame format and enabling the
Transmitter or the Receiver depending on the usage.
where are you getting that from?
the data sheet
ah
if you look up the microcontroller
begin with Ctrl+F and find the topic you're interest in
in this case USART
and you'll see it starts on page 171
scroll down to 176, on the topic of USART Initialization
I am more specifically interested right now in enabling usart from the computers side. since I want to send information through an existing framework instead of a console/logger application to be honest
then make sure you understand what stuff like Clock Speed, Baud Rate, and Frame Format is, and set them according to your needs
I am reading baout baud rate now
yeah
you enable it using #define 's and some builtins macros
implementing something like USART_Init from the datasheet
and I want to send information, for example a postion x,y on a screen to an arduino.
is that standard c library stuff?
depends on the implementation
because I can include that and it should just compile without issues
it's probably standard for arduino, whatever you're using to compile
I can just try it lol
@hoary dune oh ok mb I didn't see that
^^
the UBRRH UBRRL are the high/low parts of a 16 bit memory address
declared as macros, in the library that the datasheet is assuming should be implemented for your device
it is, then I have enabled it on the arduino
I would then need a terminal on my computer
and thats what I am most interested in
since a terminal is just a terminal. and I kind of want to use a framework so I can also do fancy stuff on the PC
but I got a feeling that stuff like that is really complicated haha
so you want to send and receive data over a usb port and interface with the arduino using the terminal?
yeah
you'll want a device that lets you pretend to be a serial port if you're communicating using uart
if you were just doing this with the arduino's usb port it'd be easy as hell
because the arduino's usb port is seen as a serial port for computers
and some standard C code as an example for communicating over such a port
I dont think you quite get what I am trying to achieve. I just want to be able to send the number 8 to an arduino using any normal c library if at all possible
I dont want to use a terminal program :V
its hard to track down any information that lets you do that. like running your own program and sending some basic info to an arduino
I wasn't aware a USB port was treated as serial and that pins 0 and 1 are connect to that USB-to-TTL chip
as far as terminal program stuff... you don't need to interface through the terminal
but you need to communicate over that serial port, and the code shows you how ;o
using these functions, specifically
thats exactly what ive been looking for holy shit xD
C is not backwards forward compatible with c++ anymore, c++ doesn't fit in the scope of C now
plus new C has all these new things that make it look a lot more like c++, if you look at only a short block of code it can be hard to differentiate it between c/c++/c#/java
Well I guess it was never completely forward compatible to begin with
oh i didnt know that, i assumed it was at the start
a lot of it seemed to be the particulars of the compiler
the fact that you'd think a universal serial bus wouldn't be Serial triggers me @orchid needle
thing is it's a bus
so you need a usb to ttl
I just didn't know the usb on the arduino was set up that way
oh finally somebody bringing arduino stuff in this channel
@long raft hear that? not everything is high level you nerd
I only worked on PIC microcontrollers
mmmh thats a bit advanced for what im doing
what are you doing ;o
mostly interfaces and other learny schooly stuff
right now actually im learning about pointers, addresses and all the other boring stuff needed to talk to stupid chips
i know but people around THESE parts probably find that tiresome
not to mention i probably learned more in an internship i got last summer than i did so far in my session lol
always learn better when you're forced to start using everything from scratch lol
ive been bringing arduino stuff in here for months disk, MONTHS ๐
buts its always just press a button, light a led kind of stuff.
@long raft hear that? not everything is high level you nerd
@timber onyx I'll be the one to bring script kiddie stuff in here dw ๐
most arduino have the usb to serial chip on board or on die
various chips wil have 1-4 serial ports
I just cant find any tutorials on how to use it though
I got as far as finding atmel's own documention for serial communication and a library called LUFA but oh my is it complicated xD
the arduino IDE examples just dont cut it anymore, they're not what I am looking for.
sorry but unless you have a specialist to explain it to you you're pretty screwed
nerds
sooo.
path finding algorithms
I have got no clue.
how are you supposed to go from one point to an array to the other
Oh I get the theory but I only get stupid java code examples
you need some kinda path map that tell the ai if it is practicable or not
how good do you need that algorithm to be?
and the ai will take the shortest path
what structures does your example use?
I have a 2d array
and a queue?
I have a 2D array at the moment.
in that you are going to need to mark tiles as checked
i whish i knew how to programm on my own
basically, go to a tile, mark it as checked, and then do the same for the surroundig one that aren't checked
still struggling to use a lcd display on arduino
thats where I am stuck at tho
if I have a position randomly in the graph, how do I find its neighbours?
maybe do like mars rovers
I havent done LCD displays either xD
calculate every path possible and take the shortest
int tilesY = 50;
int Map[tilesX][tilesY];
for(int row = 0; row < tilesX; row++)
{
for(int collumn = 0; collumn < tilesY; collumn++)
Map[row][collumn] = 1;
}
Map[6][8] = 2;
InitWindow(screenWidth, screenHeight, "Strategy game");```
you can make a queue, and add all the tiles you haven't visited surrounding the one you are in
yeah but that is the issue, how do I find the tiles surrounding me? and then recursively finding the tiles surrounding those tiles
any position inside the graph
which graph?
i = row
j = column;
surroundig tiles to map[i][j]:
map[i+1][j]
map[i-1][j]
map[i][j+1]
map[i][j-1]
are there any obstacles ?
you also have to check those aren't offlimits
so I have to check every tile around me? save those locations in an array, and then check for every item in that array locations around that?
in the array you save the tiles you have visited, you need another structure to save the ones that you are going to visit
a queue or a stack
depending which type of pathfinding you want to use
well considering I am completly new to pathfinding the most basic one imaginable ๐
@frozen oriole no obstacles yet
queue q;
q.push(starting tile);
visited[startingtile]= true;
while(q not empty){
tile = q.front;
q.pop;
if(not visited[tile]) {
if(goal) finish or save it
else{
visited[tile] = true;
for(each tileB surroundig tile){
q.push(tileB);
}
}
}
}
this is supposed to be comprenshible pseudocode
mmmh the pseudo code isnt that helpful, I am mostly stuck on how to code it and its hard to follow that.
you need to have the shape of the algorithm clear
Ive gotten this far. you get your position. then iterate through every position around you.
then you save those positions as visited? and add them to a queue to visit?
you mark the starting one as visited and save the others in a queue to visit
A*
let's not start with that
yes lets not do that
why
but how do I save a coordinate in an array. since they are technically two different integers
learning by bits, and honestly you can adapt it fairly easily
you mark the same position in the second array
so you go visited[rows][columns] = true
ah okay, so I have a second array in which I store the visited area's
yeah
you can make a vector system
I can work with vectors as well but I havent made the grid out of vectors
as a matrix is a vector of vectors you, technically, have
it does ydesiredposition-ycurrentposition and xdesiredposition-xcurrentposition
that's A*
and you got the path
its getting there ๐ฑ
oh so if youre wondering, I am using a framework that lets me make some basic C games. I use it for stuff
what are you pathfindig for?
I want to make a character move from one place to another
then you should be fine with this approach
Map[posX-1][posY] = 0;
Map[posX][posY+1] = 0;
Map[posX][posY-1] = 0;```
I got this right now, but do I now need to save each position after it changed in an array?
you need to save them before marking them
I am having a really hard time wrapping my silly brain around that
if you want your code not too look like a mess you can set up
const int directions[4][2];
directions[0] = {1,0};
directions[1] = {-1,0};
directions[2] = {0,1};
directions[3] = {0,-1};
and then
for(int d = 0; d < 4; d++){
pos[posX+directions[d][0]][posY+directions[d][1]] =...;
}
that is for later
yeah, I am going to have to wrap my head around every step first before I can loop it
the first step is just that:
am i there yet?
ok, i have been here, i will have to go to this places around me
how do I find it if I've been somewhere? I marked it as 0. do I now need to check for every 0 and if so, look around that?
you usually initialize the second array as not visited
and mark every place you visit as visited
wow, this is getting complicated
I know ๐ญ
imma head back to my blinking led on arduino
its not okay how complicated it is
you could try to manually emulate BFS on a graph, try if it helps you understand
I marked it as 0. do I now need to check for every 0 and if so, look around that
no, you need to remember the places around the one you marked as zero
okay so everything time we make a 0. we save that location?
okay, but that still means I got to check every location around that zero. which still means I need the location of the zero right?
the first one you decide it arbitrarily , and the next ones are the ones you saved
so you shouldn't have to search for a zero
No I mean. we have that location. that is saved. and then check around that location.
or am I being retarded?
save the tiles around that location, to check them later
how do I save the tiles around that location?
C
that makes it complicated
I could use c++ as well since its accepted code
but I am not known in c++
I only know how to use structs
so you can use any c++ library
yes?
#include <queue>
compiles?
you can always implement one manually.
Any other way to implement a FIFO structure?
you could do something with an array
I Can't help you getting the C queue on your environment, but i can help you making a homemade one
array 0 is first out. shift everything index - 1, add something at the end
alternatively you could also go with the equally complicated less efficient but queue less version
for a array queue, you can also copy C and do it with two indexs, a index for the first out and another for the last in
yes i was wondering why use a queue when this could be done more easily with a longer code
I figured something should be recursive
eeeh i might not completely understand what you need then
oh i thought you just wanted the thing to move when you pressed the arrow keys
oh then that is beyond me, ignore what i was saying
DFS uses a stack instead of a queue, and since recursivity is a call-stack no extra structures are required
DFS makes a beeline for one corner, then a beeline for the next one and so on
it looks really stupid to have a character moving that way, but it gets there
the goal is to know which is the first step to take, BFS you can trace back which was the first one that lead to this path, in DFS you will probably find it with the first one you check
#include<conio.h>
int a[20][20],q[20],visited[20],n,i,j,f=0,r=-1;
void bfs(int v) {
for (i=1;i<=n;i++)
if(a[v][i] && !visited[i])
q[++r]=i;
if(f<=r) {
visited[q[f]]=1;
bfs(q[f++]);
}
}
void main() {
int v;
clrscr();
printf("\n Enter the number of vertices:");
scanf("%d",&n);
for (i=1;i<=n;i++) {
q[i]=0;
visited[i]=0;
}
printf("\n Enter graph data in matrix form:\n");
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
scanf("%d",&a[i][j]);
printf("\n Enter the starting vertex:");
scanf("%d",&v);
bfs(v);
printf("\n The node which are reachable are:\n");
for (i=1;i<=n;i++)
if(visited[i])
printf("%d\t",i); else
printf("\n Bfs is not possible");
getch();
}```
I hate that its so obfuscated though. for my eyes it just uses random letters to name things
that is hideous
bfs(q[f++]);
and yeah, it uses a array and two indexs as queue
afk.
@coral sundial back, want to continue trying to adapt that?
@coral sundial
So for the home-made queue, you need a long array of size 2 arrays, and two indexes (front and back), push is saving in the back position and increasing back, front is just reading front and pop is increasing front
can you use structs you said?
so for every tile you want to save :
queue[back] = {posX, posy}
back++;
Will do
alright so i know absolutely nothing of high level programming
does anybody know how unity engine files work
You put them in a folder and is read by the unity engine
This needs more precise wording @timber onyx
ok how do you open a unity file without using the engine, like you were opening the code to a blinking LED light to check the frequency or something
i really know nothing about how this works
you know what, i might just be looking at it wrongly
@coral sundial I missed the convo earlier but for pathfinding I think the big ones are Dijkstra's algorithm and A*
might wanna look into those
yeah but the tutorials are pretty advanced
and often use obscured names for integers
A* is pretty straightforward no?
Welcome to the first part in a series teaching pathfinding for video games. In this episode we take a look at the A* algorithm and how it works.
Some great A* learning resources:
http://theory.stanford.edu/~amitp/GameProgramming/
http://www.policyalmanac.org/games/aStarTutori...
yup but its hard reading code that has names for integers such as dsf(adj[a][i]);
following this one at the moment
still lost at how to make the queue
which coding language is this for?
c/c++
but I am not fluent in C++ syntax
using things like std::namespace is lost on me
A* algorithm ๐ข
I see alot of comments to add too much explantion
and codes with things like [i-1][j-1]
which is imho really hard to read
once you know what it does
it's a double nested for loop
to itterate through the entire array
so I is the row, J is the column
what is hard about that?
I and J is the current Cell
[I-1][J-1] would be the cell to the NW of the current one
in 2D space atleast
Yes, it's overcommented but it's a tutorial to explain into the smallest detail how it works ._.
funny thing tho they made a mistake in their graphic ๐
anyways, if it makes any more sense.... f is basically the cost of the entire path from point A to point B
f = g + h
besides that, I am mostly looking for something that just looks through the entire grid at the moment, since that is where I am struggling
g is the previous node, h is the current node
but I got something in my mind now
lets just leave constructing a path for another day xd
I mean your question was about pathfinding :p
pathfinding isn't easy until it clicks
then it's not that hard :p
yeah, so baby steps xd
you were on the right track tho
you wanna map the positions around your current position
and figure out which one is closest to the target
I get it somewhat.
- you have a start position. add that to a list of open positions
- check around you, add those tiles to the list of open positions
- remove the tile you just checked and add it to closed positions
but now I need to know how to construct a list.
which could be a simple array i guess??
yes
in the example I linked as well
example
isUnBlocked(grid, i-1, j+1) == true) ```
again, itteration over those arrays
which is I think just checking your tile and checking if its valid. if so add it to open positions, if not add it to closed positions
maybe this will make more sense
the thing I am also struggling with is that I am pathfinding through a map array that I also use to draw textures with
mmmh
can't you just convert the array to a binary array?
if it's a tile that is blocked = 0
if it's a tile that is accessible = 1
mmmh
yes
I think so
every location in the array could refer to a structure that contains more info about that terrain type
so basically you got something like
tileData.walkable
that is either 0 or 1
also sorry I haven't used C++ in forever
I'm so used to javascript nowadays ;-;
Ew.
yea I know
yeah, and then loop over the array and check for every tile if its walkable or not. and then add that to a pathfinding data array
yup
basically just project it to a new array
yea I make shitty scripts for a browser game don't shoot me ๐ญ
I usually keep that pathfinding array cached somewhere kind of like a layer because I often need it around.
I'm not a programmer
I aint either
I learned C to code arduino's with
I dont know how any of this schmancy c++ stuff works
I'm been writing a turn-based strategy for a month now in Rust. I began writing the design document last night as a way to formalise the project.
Right.
I'm looking into unreal engine atm
before you ask. the arduino languange is bad. it abstracts perfectly fine c code and leaves out the more powerful stuff
I studied character design so I have a small amount of knowledge of it
but wanna see how much I can do with the blueprint technology
So, often the pathfinding layer contains information like:
Is the tile see-through?
Is the tile physically solid or otherwise unwalkable to me?
Etc.
honestly, I use raylib. its a c/c++ framework. it provides alot of the basic functions to make a simple game
the only 2 games I ever made in C++ was a bomberman clone, and a candy crush clone
I dont need to use UE right away ๐
for assignments
I hated programming back then
I got into it again making scripts for a browser game called tribalwars LOL
That's my project right now.
Well they're older screenshots but it's mostly the same.
back to A*
I have all these ideas but knowing the effort that goes into it
it's like.... o god what am I getting myself into
I have an open list. I have one coordinate in it. 0,0
if I go to 1,0
I then need to add that to the closed list
how do I do that
another integer to hold that value?
Motivation to start? Usually it's the middle part that gives people trouble.
I think you just have to make the entire list the exact same coordinates
like
if 1,0 is closed, then put the 1,0 in closedList to 1
A*(star)
Welcome to the first part in a series teaching pathfinding for video games. In this episode we take a look at the A* algorithm and how it works.
Some great A* learning resources:
http://theory.stanford.edu/~amitp/GameProgramming/
http://www.policyalmanac.org/games/aStarTutori...
trust me
look at that video
๐
That's a good one.
it explains it super well
I can give you another one as well.
Just saying, written documentation of A* is really... shit.
cause the idea of what happens behind the scene is way easier to explain visually
cause after all, its a path you are trying to draw on a tilemap
A tricky one to do a video about this, but here is an tutorial implementation of the A* path finding algorithm, programmed in C++, running at the command prompt.
Lol, forgot the source: https://github.com/OneLoneCoder/videos/blob/master/OneLoneCoder_PathFinding_AStar.cpp
Blo...
yeah but I am having an issue with visiting tiles and saving their coordinates
How so? Can you maybe show me your source code?
I need something to hold the start position. then go up. save that position in an array. then go left use that something to save that value and add in an array. and then do that again untill you have found a path/matching coordinate
but like, everytime I check a tile, I need that coordinate. and save it
and how did that vector queue go?
in this line?
queue[back] = {posX, posy};
yes
and you declared queue as
int queue[100][2];
yes
you may have to do
queue[back][0] = posX;
queue[back][1] = posY;
due to C not helping
yep, C doesn't like the first one unless you are declaring the array
mmmh
if you can do structs you can alway declare it as a vector of structs with a posX and a posY
I have acces to vectors
C vectors don't seem to change this much
i mean if you arent using small project boards why even use it
in school i learned to use some cool industrial code languages
real professional stuff i tell you
labview beats arduino by miles
hell even the ISS uses labview
oh I have no doubt
arduino IDE is hobby code at best
you should move on to C as soon as you can though. the data sheets arent that intimidating anymore once you get comfortable with setting flags and banks
youre also closer to the hardware that way and can manipulate it to your hearts content
yeah i got to use C in one of my classes
honestly i loved the extra control it gives you over the small details
how to understand A*: copy someone elses code
it still doesnt work
I mean its something ๐
how the hell are you doing A* on C
pretty memory hungry but not too bad
And it is pretty intuitive too.
It does kill the performance of A* but it has the advantage of not using any complex containers and finding the same path.
yeah but its not working yet on my end
it isnt interating past the initial 9 tiles
I havent fully implemented it yet though
I was hoping I could skip the g f and H nonsense
there is also this little thing where I cant use bools so I declared FALSE 0 and TRUE 1
how do you look for current node without costs?
what this is doing is it is marking on a 2nd matrix with a lot of data, all the neighbouring tiles as "open" and a cost to each
then he marks that one as visited and searches all the second matrix for the lowest cost open tile
then grabs that one as active and repeats
mmmh
He is looking for the lowest cost tile with
for(int x = 0; x < tilesX; x++)
{
for(int y = 0; y < tilesY; y++)
{
Nodes[x][y].f = Nodes[x][y].g + Nodes[x][y].h;
if(Nodes[x][y].OnOpen)
{
if(Nodes[x][y].f < lowestf)
{
currentX = x;
currentY = y;
lowestf = Nodes[x][y].f;
}
}
}
}
// we found it, so now put that node on the closed list
Nodes[currentX][currentY].OnOpen = FALSE;
Nodes[currentX][currentY].OnClose = TRUE;
I changed the code a bit
right?
yes
if you do that without costs you will have a weird DFS, which will make a weirdest path, but should work
you also have to decide if you allow diagonals or not
Oh I copied the calculations now too
but its not going past the initial 9 tiles. atleast its not drawing past them.
because I dont fully understand where he selected the tile
or do I?
its in the function I just copied
problem with that is that he doesn't seem to reset lowestf, and f will be increasing trough the nodes.
try adding int lowestf=10000; above that code
right under the while loop?
yes
so I am having an issue. what its supposed to do is make the active tile a value of 3. I did that by adding a line of code right underneath putting it on the closed list
I am also just constantly trying to calculate the same path
should I make it run once by pressing space?
Not quite getting you here
should I make it run once by pressing space?
advance one step?
its in my game loop, so its constantly called upon with the same values
so once its finished finding a path, it does the rest
then goes back into the loop and does it again
but that shouldnt matter
because its changing the tiles in the while(!Nodes[currentX][currentY].OnClose) loop
that loop has the wrong entrance condition now that i look at it
it should exit when it's finished
xD
change it for
(currentX!=endx || currenty!=endy)
What is OnClose?
it is a propierty of the tile that marks it as closed
onclosed
not ready to visit or already visited
So wouldn't you rather call it closed or is_closed?
it is meant to simulate a list
and the program moves tiles from the closed list to the open and then back
That seems way more complicated than the usual implementation I see.
the thing is that it doesn't use queues
Can somebody link me the source? It's hard to get an idea of what is going on.
oh you got it from the blog
the one on the forum has several bugs
Source code.
Okay, cool.
int STAR(int StartX, int StartY, int EndX, int EndY)
{
int currentX = StartX;
int currentY = StartY;
int lowestf = 1000;
Nodes[StartX][StartY].OnOpen = TRUE;
while(currentX!=EndX || currentY!=EndY)
{
int lowestf = 1000;
//look for lowest F cost node on open list - this becomes the current node
for(int x = 0; x < tilesX; x++)
{
for(int y = 0; y < tilesY; y++)
{
Nodes[x][y].f = Nodes[x][y].g + Nodes[x][y].h;
if(Nodes[x][y].OnOpen)
{
if(Nodes[x][y].f < lowestf)
{
currentX = x;
currentY = y;
lowestf = Nodes[x][y].f;
}
}
}
}
// we found it, so now put that node on the closed list
Nodes[currentX][currentY].OnOpen = FALSE;
Nodes[currentX][currentY].OnClose = TRUE;
Nodes[currentX][currentY].tile = 3;
for(int dx = -1; dx <= 1; dx++)
{
for(int dy= -1; dy <= 1; dy++)
{
if(!Nodes[currentX+dx][currentY+dy].OnOpen)//its not on the open list
{
//add to open list
Nodes[currentX+dx][currentY+dy].OnOpen = TRUE;
Nodes[currentX+dx][currentY+dy].OnOpen = FALSE;
//CHANGE TILE TYPE TO 3
if(dx!=0 && dy!=0)
{
Nodes[currentX+dx][currentY+dy].g = 14;// diagonals cost 14
}
else
{
Nodes[currentX+dx][currentY+dy].g = 10;// straights cost 10
}
Nodes[currentX+dx][currentY+dy].h = abs(EndX-currentX+dy + EndY-currentY+dy) * 10;
}
else //its on the open list
{
//CHANGE TILE TYPE TO 3
if(dx==0 || dy==0) // if its not a diagonal
{
if(Nodes[currentX+dx][currentY+dy].g!=10) //and it was previously
{
Nodes[currentX+dx][currentY+dy].g = 10; // straight score 10
Nodes[currentX+dx][currentY+dy].h = abs(EndX-currentX+dy + EndY-currentY+dy) * 10;
Nodes[currentX+dx][currentY+dy].f = Nodes[currentX+dx][currentY+dy].g + Nodes[currentX+dx][currentY+dy].h;
}
}
}
}
}
}
return 0;
}
Wait what?
I havent added parents
Where is Nodes first declared?
{
int tile;
int OnOpen;
int OnClose;
int f;
int g;
int h;
} Nodes[25][25];```
Global matrix of structs
It would have been like ten extra characters.
ssh
it is C, you have to unreference at every step
so one character per time Nodes is used
I am familiar. I've written C and C++ for almost ten years.
struct Node
{
int tile; // Is this the index into the map, tile ID, type of tile?
int OnOpen;
int OnClose;
int f; // This is F-Cost?
int g; // G-cost?
int h; // H-cost?
} Nodes[25][25];
yes to all
Thanks.
tile 1 is a grass tile. tile 3 is just nothing
Does nothing also mean solid?
And these must be more globals, right?
tilesX, tilesY
They are the width and height of the map in tiles?
yes
To save me some time, do you get any debug information like where the crash occurs or is it just a silent segfault?
I'd have to look into the debug mode first...
it probably happens upon running a star
I could add a button before running it
So what is the value of tilesX and tilesY? 25 and 25?
what happens if you look outside the array?
I'd expect a crash.
the code doesn't controll that
yeah I'd expect that as well
as in, it looks everywhere
so I'd have to add in a check
yup
ive done that in the past with a simple array and a pointer comparing it to the memory adress
In this loop here.
for(int dx = -1; dx <= 1; dx++)
{
for(int dy= -1; dy <= 1; dy++)
{
if(!Nodes[currentX+dx][currentY+dy].OnOpen)//its not on the open list
{
You aren't bounds checking.
Let's say currentX and currentY is zero.
That means you'll be indexing -1, -1 at some point.
And a few other outside-bounds indices as well.
I guess you can use memory directions to check that
I used memory at the time because I didnt know what to compare it too. and it was for selecting a menu.
I would do it by ensuing the coordenates are between 0 and 24
it is so mods don't have to click everything
it is ||
Ah. I'll just write or
int nx = currentX + dx;
int ny = currentY + dy;
if nx < 0 or nx >= tilesX or ny < 0 or ny >= tilesY {
continue;
}
This ensures you don't process any tiles that are out of bounds.
if it is equal it will still be out of bounds
Yes. I wrote >=.
so you will be allowing the reference Nodes[25][25]
That snippet skips the current iteration of the inner loop.
No I won't.
If nx == 25 or ny == 25, it will skip.
yes, My Bad
We only want the interval [0, 25).
where do I check for out of bounds? I am not updating any values dx, dy except for the two nested for loops
at the start of every inner loop
Let me integrate it in then.
for optimization sake, youd calculate startx and endx, and starty and endy before the loop, and not introduce an extra branch inside every iteration of the loop
optimization comes later
even for debugging
Also you want parenthesis around predicate in the if.
I've been writing Rust for a while so I forgot.
you guys are mandatory curly brace people huh? even for a single continue statement? 
I will have to update NX and NY before the if statement inside the inner loop?
@long raft are you talking the whole program or this snippet?
in general
Is this in C or C++? I'm curious to know before I type something.
not the curly things, the endx, startx
C
oh, yes thats in general too. as a rule of thumb dont add extra calculations per iteration
and it will make it harder to debug that particular line, in my opinion
I mean, the program already has a EndX so i was confused
if statements are more costly than people generally expect, and i mostly bring it up because its C
and how do you skip the middle tile then Derp?
oh i just mean precalculate the domain of the for loop, dont check bounds inside the loop
oh i guess for readable code, in that case you would put in the if statement
the domain is not a linear memory portion
but for bounds checking, you dont need to do that in the loop itself
F
if you calculate it from directions general indexs or memory positions won't help
I need to add it to the first nested if loop
for(int dx = -1; dx <= 1; dx++)
{
for(int dy= -1; dy <= 1; dy++)
{
// Shorthand relative coordinates.
int nx = currentX + dx;
int ny = currentY + dy;
if (nx < 0 or nx >= tilesX or ny < 0 or ny >= tilesY) {
continue;
}
if(!Nodes[nx][nx].OnOpen) //its not on the open list
{
//add to open list
Nodes[nx][nx].OnOpen = TRUE;
Nodes[ny][ny].OnOpen = FALSE;
//CHANGE TILE TYPE TO 3
if(dx!=0 && dy!=0)
{
Nodes[nx][ny].g = 14;// diagonals cost 14
}
else
{
Nodes[nx][ny].g = 10;// straights cost 10
}
Nodes[nx][ny].h = abs(EndX-currentX+dy + EndY-currentY+dy) * 10;
}
else //its on the open list
{
//CHANGE TILE TYPE TO 3
if(dx==0 || dy==0) // if its not a diagonal
{
if(Nodes[nx][ny].g!=10) //and it was previously
{
Nodes[nx][ny].g = 10; // straight score 10
Nodes[nx][ny].h = abs(EndX-currentX+dy + EndY-currentY+dy) * 10;
Nodes[nx][ny].f = Nodes[nx][ny].g + Nodes[nx][ny].h;
}
}
}
}
}
Change or to ||.
you only added it while looking for an active tile?
maybe i'm not understanding you @long raft , can you write a small loop that gets all 8 tiles surounding a tile i,j with your optimitzation?.
so where you have dx = -1 as the starting index, you would calculate just once where it's safe to start. It might be 0 instead of -1, and you do the same for the upper bounds
so check if the starting tile is in a corner before checking everything else
code did work right out of the bat
ya basically. you can do it later, its not a big deal
got you
this is some serious headcracking
same crash?
crashes right as I run the algorithm
what kind of crash
freezes
like stuck in the loop?
I think so
can you break and see where it is?
well YES
great idea
{
for(int y = 0; y < tilesY; y++)
{
Nodes[x][y].f = Nodes[x][y].g + Nodes[x][y].h;
if(Nodes[x][y].OnOpen)
{
if(Nodes[x][y].f < lowestf)
{
currentX = x;
currentY = y;
lowestf = Nodes[x][y].f;
break;
}
}
}
}```
doesnt check out of bounds here
and it crashes
its global
Is it initialized?
for(int row = 0; row < tilesX; row++)
{
for(int collumn = 0; collumn < tilesY; collumn++)
{
Nodes[row][collumn].tile = 1;
Nodes[row][collumn].OnOpen = FALSE;
Nodes[row][collumn].OnClose = FALSE;
Nodes[row][collumn].f = 0;
Nodes[row][collumn].g = 0;
Nodes[row][collumn].h = 0;
}
}
so tilesX and tilesY can exceed the array size maybe?
column* >:)
If you run that, it should be initialized
does it matter, row and collumn are 25
shouldnt it be Nodes[collumn][row]?
oh.
err nah its fine the variables are just named backwards
have you copied this? @coral sundial
https://discordapp.com/channels/203512636556574720/523401134107525121/702308850937757797
yes
that accesses to Nodes[nx][nx]
but it doesnt crash there? it crashes at the first for loop
my C balls itch when i see
if(dx!=0 && dy!=0)
{
Nodes[nx][ny].g = 14;// diagonals cost 14
}
else
{
Nodes[nx][ny].g = 10;// straights cost 10
}
instead of
Nodes[nx][ny].y = dx!=0 && dy!=0 ? 14 : 10;
it doesnt throw anything into the console
it freezes, excuse me
thats probably a big difference
so you stopped it one time and it was in the first loop
yeah
that could mean it is repeating the whole loop
actually, it breaks right into the first for loop
i think if you put a break after the loop you will see that it completes it
while(currentX!=EndX || currentY!=EndY)
{
int lowestf = 1000;
//look for lowest F cost node on open list - this becomes the current node
for(int x = 0; x < tilesX; x++)
{
break;
oh what!
it freezes before that break;
do you mean for break to escape the while loop? because break will exit the for
breaking the while loop actually works
ive never understood why languages dont include something like break 2; to break out of 2 loops
but if you write break inside a for loop, it will not break out of the while loop
it breaks the for, it goes back into the while loop, which has the same conditions
so uhh when i said break, i meant use a debugger break, to pause it
not the actual break command
๐
if you dont have a debugger you can break, just use output messages somewhere, console or log or whatever to confirm it gets to places
What's tilesX's value?
you don't want to use break commands in those loops anyway, it is a search
Since it freezes, that while loop must keep going forever. How's CurrentX and CurrentY being updated?
You know I really appreciated you all trying to fix ''my'' code but I really want to sleep.
I might as well learn proper c++ tommorow xD
and use a queue to do a neat BFS
whats wrong with C?
c++ has a lot of things that make your life easier IMO
besides that, I dont know why I use a* anyway. a BFS works fine as well. when I sleep on it I can probably get my brain around it better tommorow
because today was just a wtf day
i have no idea why you'd need to use C other than in applications where every bit of memory is needed
or if you're just old idk
C is dope and a great stepping stone for Cpp which can be awesome if used properly
beep boop
int STAR(int StartX, int StartY, int EndX, int EndY)
{
int CurrentX = StartX;
int CurrentY = StartY;
while(CurrentX!=EndX || CurrentY!=EndY)
{
//find an open tile
for(int x = 0; x < tilesX; x++)
{
for(int y = 0; y < tilesY; y++)
{
if(Nodes[x][y].OnOpen == TRUE)
{
CurrentX = x;
CurrentY = y;
}//if open tile
}//for2
}//for 1
//open tile is found, now close it
Nodes[CurrentX][CurrentY].OnOpen = FALSE;
Nodes[CurrentX][CurrentY].OnClose = TRUE;
//check all tiles around the current tile
for(int dx = -1; dx <= 1; dx++)
{
for(int dy= -1; dy <= 1; dy++)
{
if(TRUE)//check for out of bounds... how?
{
if(Nodes[CurrentX + dx][CurrentY + dy].OnClose == FALSE)
{
//open that tile if its not closed.
Nodes[CurrentX + dx][CurrentY + dy].OnOpen = TRUE;
//switch the texture to ''open''
Nodes[CurrentX + dx][CurrentY + dy].Tile = 3;
}
else
{
//its closed, dont check it.
}
}
}//for2
}//for1
}//while
return 0;
}
pathfinding attempt #2
currently stuck for how to check its not going of the grid
I also realize this algorithm is biased for finding a path toward the lower right corner. problem for another day
this looks like a dick
shut the fuck up kas
this looks like a dick
https://i.imgur.com/tTc9cKQ.gif
when you git rebase and squash to the first commit and force push
@coral sundial
int w = dx+CurrentX; // the column
if ((v>0) && (v<tilesY) && (w>0) && (w<tilesX))
{
}```
if you want to check the bounds
\
Is anyone here still writing in pure C?
I like objective languages but. C is just C fun to code.
I code in C too often for my taste
I like being masochistic
interesting behaviour. it tries to construct a path through an obstructed tile. even though that tile cant have a parent or someone linking to it
I dont know what the hell is happening on the left to be honest
okay I get it. the left path is the correct path. but when it reaches an obstructed tile its parent is suddenly way up there
Can anyone here help me with Unreal Engine?
It has to do with assets
I was wondering if anyone knows how to make cook an asset but it comes out only as a .uasset file
not with a .ubulk and .uexp file
I believe those are called dependencies and its really annoying me
@amber sail why do you need to package the files together?
.uasset = header information
.ubulk = data that can loaded into memory using level streaming
.uexp = data that is loaded into memory when a level is started
They're organized in a .pak in a way that facilitates more optimized loading speeds.
@orchid needle I need them packaged together because that's how foxhole packages theirs
Is it possible?
Oh interesting. Perhaps look into using UE3; a brief google search tells me you could cook the assets either into one file or separately using it and that the .ubulk data is located after the header & non-streamed data
Hmmm I'm not sure how well that would work
Because Foxhole is in UE4
And I don't know of a way to convert the textures afterward
Why not ask the guy behind the sound mod
wdym?
The spiderman thing? I dunno nvm xD
lol
But yeah i have been in touch with him
He was the one who helped me get this far
but ive run into this issue
which is the last think i need to fix and then textures in foxhole galore
Are you cooking it through the editor ui or frontend/commandlet?
Just wondering if there's command line params for it
@native kernel Still looking for Dev assistance. No rush, but if any of you guys could tell me how you guys cook your textures it would make my day.
tfw you try to output an image file into a url field and it outputs the whole file as string
nice
Numbers, many numbers. Hypnotizing.
Spot two same numbers
@barren quarry is that a string of coordinates
I am too drunk to think straight
lets be honest
OHHHHHHH
those are binary values of the color?
could be
Common low/average fidelity image formats are encoded as a series of 8-bit numbers, and their ordering corresponds to what channel they pertain to (red, green, blue, alpha, cyan, magenta, yellow, black, etc). Most images used on the web are also encoded for compression, using a variety of discrete transformations. If you're keen on the topic, you can look up DCT, DWT, EZW and see how some images might be stored and why reading some image file formats isn't as easy as pulling out pixel-by-pixel values
looks like a byte array โ
^ it looks like a byte array ye. If you want to check if it's decoded you can see if it has jfif markers at the beginning if you think it might be jpeg format, or just try rendering it xD
tfw you try to output an image file into a url field and it outputs the whole file as string
@barren quarry you're in the matrix now
was she wearing a red dress?
Im surprised that it outputs in decimal and not hexadecimal
Are there languages where dates and times don't suck?
and formats*
They always suck because every language does it different and messes with your brain @scenic river
I dont even think about programming times, because half the time it all is just extra work
Like, I used a Python library to get the time difference in a set of measurements (read: the test took a minute or two, but the counter did a hour:min:sec format). As not to have to write an annoying piece of code translating all the minutes into seconds, I thought being smart interperting it as datetime format. Except I had to add years months days to it, and had to do a lot of formatting crap and, jn the long run, it def was not worth it
And I got the luck all the data was in the same format
The biggest struggle is working with dates originally from a excel worksheet, as sometimes it preinteperts things as time stamps and reformats them, but not all of them
Date formats just suck
I make scripts for a browser game
and they need to work on different markets, some have the month before the day, some after, other languages... regex can only do so much lmao
//define current x and y.
//create queue for current x and y
//create a priority queue.
//calculate Fcost for starting node. starting G cost is 10 + calculate H cost form start to finish.
//add start to queue
//while(CurrentX != End.x || CurrentY != End.y)
//get current X and Y from priority queue
//empty? get current x and y from open queue
//empty? return FALSE. path found or no more valid nodes;
//for current X and Y calculate F cost. = get F cost.
//check if neighbour is out of bounds.
//for neighbours calculate F cost.
//do not visit if visited. do not check if not walkable.
//set parents for neighbour.
//calculate neighbours fcost.
//compare F cost to current cost.
//fcost lower than current? add to priority queue. close the visited tile.
//set fcost as current fcost. keep looking.
//fcost not lower than current?.
//close the visited tile. its not worth it right now.
//fcost equal?
//add to open list.
//close the visited tile?
//already visited?
//is the fcost equal to current?
//add it to the open list
//is the current fcost lower?
//add it to the priority queue
//else keep it closed.
//repeat until path found OR all tiles have been checked.
Okay I almost capable of making an A star pathfinder
I need someone to see if this plan is correct
oh I see things might go wrong with the equal f cost. if it updates and its better it wont be removed from the open queue
maybe I should take a step back and make it find the cheapest tile every time. not entirely optimized I guess
if only that was so easy
in my example, I have to parse the date from a website, and they don't keep the date in the DOM. It gets passed along from the server, but doing a request to the server to get the current server time, returns local time, rather than the correct server time. So the solution I had to do was parse from the damn html, and considering the site looks different on different markets/localised translations, the time formatting is different every time >_>
bottom left is server time ๐
oof
@coral sundial also, interestting choice of method, but I wonder why it has to check if it has already visited the tile, because that one should be less usefull to reach it path in all cases right?
a new path mightve been found thats cheaper
thats why you update it
but its going to cause issues I think with making a path
oh, in that sens
I would rather try doing it without using that part
like in a stationary obstacle situation
and then try it for a moving obstacle situation
and then in a moving target situarion
crack
is doable
you just have to refind a path if for example a wall has been build
a* is quite fast so it isnt much of an issue
that is not how the concept of babysteps works
thats now how teenage steps work either
spot the broken law of physics
Resistor goes into space? @timber onyx
what do the numbers on the diode mean, like 1,2,3,4,infinity?
is that a diode?
and if its a diode can it have negative voltage?
jesus its been too long since ive learned anything about electronics
Input outputs i guess
@languid harness 96.8 farats would break several laws of physics
@long raft itโs an op-amp

The 8 pin is just sideways so it looks like an infinity
The program simulates actual electronic components
error = goal - measure;
summ_errors += error;
variation_error = error - previous_error;
command = Kp * error + Ki * summ_errors + Kd * variation_error;
previous_error = error```
oh lol, idk. I am no EE, I am ME. I see wavy line not connected to anything, I assume it doesnt count
Because if you remove all letters, this could go for a spring demper system with the triangle being some weird exciter
im learning about toeplitz matrix calculation on gpu and my head hurts
@long raft basically a PID regulator makes sure that an output that you want to reach a certain value wont do it stupidly. first it calculates the error proportionally to the goal you set, then it sums these errors to create a global error so that when the output comes close to the goal it wont slow down drastically and then it calculates the variation between the current error and the last error so that the output wont overshoot the goal too badly. it sounds a lot more complicated than it is
oh PIDs! I know those! Sadly!
zoomers aint get any references 
reimplementing feed forward neural networks on gpu from scratch, not a pleasant experience
Oh god feed forward. People I am trying to escape model engineering by going on discord to be repeatedly be punched in the face
oh noes a programmer has to do something original
lol
not just original - math intense
i rather prefer working in trig, ive only had 2 classes on linear algebra and its a daunting subject
oh yeah linear algebra is annoying
it's one of those things where you can relearn it a million times but you'll never remember everything about it unless you use it every day
yea or you just use something pre-written to do it for you like a graphing calculator or library
my naive algorithm is slow AF
but where's the fun in that 
ive known a lot of programmers who somehow snuck through their math work - when they find something math intense they just hack it some other way
well hey if it works it works
plus i know the feeling of not wanting to do the complicated way even though it might be the less time consuming one
more human hours, less gpu hours
yah @exotic chasm a commit is fine, at least we'll have the cooperation pipeline figured out that way
@long raft Alright i think i got it after struggling a bit. Never used git or github before.
Should be a "pull" request or whatever
sure, useful learning experience; i can help if you get stuck anywhere
wow seems like you figured that out hella fast
only took me a year to learn git
The lingo is heavy
yea its rough
oh shit my A* found a path
we need a real javascript/nodejs wiz chad that i could just make demands on
trying not to learn node while just making a million small changes is frustrating

foxhole in-game GPS when
Well, it depends on the type of code. Python is an easy one compared to Java being a hard one. So it really depends on what you want to accomplish.
Python3 gang!
Boolean logic gang!
C gang
C is by far the easiest to learn but you cant do much fancy stuff with it.
easy to learn impossible to master
Boolean logic is by far the most simple but also the most complicated programming system
sounds simple, stuff can be on or off
untill you write a path finding algorithm xD
I think C and Python are both easy, depending how familiar you are already with programming
Imo every programmer should learn C so that they can better their understanding of how computers function at the bare metal. Most other languages under all the abstractions will always end up calling code compiled from C or C++.
The same could be argued for assembler
That knowledge doesn't hurt either, sometimes you need to step through the dissassembled code to discover some hidden gotchas that the compiler gave you. Also a requirement if you want to get into programming emulators.
CAN Someone explain to me what does this code actually do and whay does it do this
you have a pointer to the first element of A, + (b modulus 8)
if I read this correct
the more important questions is, what is your code supposed to do?
32 % 8 = 0
and a + 0 = a, so +(b%8) does nothing
so it prints out a[0] which is 9
and it makes coffee
int a[] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
This line declares and defines an array of a complete type 'int' (incomplete types such as 'void' or classes without a definition cannot be declared in this way - you'd need to derive a pointer instead) and initializes it using a brace-enclosed list.
int b = 32;
This line declares and defines an integer, and initializes it to the rvalue 32 (value categories are a different topic but I suggest you try to understand them as well).
printf("%d", *(a + (b % 8)));
Operators such as +, %, and * are special names for built-in functions (addition, modulo, multiplication/indirection respectively). In this case, * is being used as a function with a single parameter that corresponds to the unary dereferencing operator overload. * a, a*b, a?b:c are examples of the * and ?: operators and use their associated unary, binary, and ternary functions according to the parameters supplied next to their symbols.
I suggest you look at https://en.cppreference.com/w/cpp/language/operator_precedence if you want to understand more about what each operator does and in what order.
@rain gazelle
But yeah, as was already said: 32 % 8 resolves to 0, is added to a (an array) which returns a pointer of that array's type (int*) at that offset (in this case, 0, so the first element in the array), and returns the value at that memory address using the indirection/dereferencing operator which the printf functions attempts to parse as a decimal signed integer value
don't do his homework
Understanding the semantics of array indirection shouldn't qualify as comp sci homework. Important part is understanding that arrays are just consecutive memory addresses that you can perform arithmetic on.
Also grats rem xD
thaaanks xD
at this point I am just coding c++ but with my own additions instead of standard c++... queue's, lists... constructors deconstructors. coded it all myself xD
I still have to write a function to clean up constructed lists. I am pretty sure if I dont do that I have a memory leak there
with coded myself, I mean half pasted from the internet
What makes you pretty sure and not 100% sure :o
the fact that ive never had to take that into mind xD
I also tried listing all out points but I dont see the list increasing. but this could be due to the fact that each time the algoritm runs a new list with a new adress is made
do you have this on a repository somewhere, I'd be really interested to look at it xD
Never worked with repositories
but its all in its own file
I mean almost all
the entire thing runs on raylib. I have main.c where I call all functions from. then a pathfinding.c and a list.c and then a header for the structs
oh
but I can give you a main where I tested the lists
sure ;o
Ididnt code half of it now that I look back on it. I made some modifications to popnode so it returns data instead of deleting the node
and the printlist function is almost entirely mine
If I only knew how double pointers work
and now that I think about it. I could modify print list to delete every need it goes over.
you only return data from the popped node if the head is the popped node?
Yep
I only need to pop the head node so far
Since the important nodes are pushed infront they get popped first
Now for an optimization i could indeed look for the lowest fcost node in the list and pop that one
do you call pushLast often?
Only when the fcost is higher than that of the current node
I would wrap this up in another container and keep track of the head, so that you don't need to traverse the list over and over
{ ... } ```
and if you made that container (i.e a list, and had the current 'list' struct become a 'node' struct) you could move those functions to be static member functions
and then you could template them so the data isn't limited to being int
Yeha so where i copied to code from initially they had a generic linked list
But i wanted to try and imitate it rather than copy
and the int array[5] declaration doesn't need to have an explicit length, the aggregate initializer sets it anyways
other than that nice ^^
So i took a bit of a cut and made int for now
a pointer to a pointer ;o?
**head is a pointer to a pointer for the first node, which gets its adress passed
Which i dont really understand what a double pointer does in this case
so the address of the pointer to the first node is passed in as an argument to the first parameter of a lot of the functions
I guess the best way to think about it
is if there was no second asterisk
Mmmh
you'd be passing a copy of the pointer, and the original remains unmodified
I bet it has something to with the that the list is also a pointer
Is there a concept behind this i can google tommorow?
Like pass by value or something
Passing references to pointers
Oh wow, you made your list with pointers, neat
no problem ^^ gn
also if you look back here later, for more insight into why it's necessary:
*node = new_list;
If you simply did node = new_list and didn't have a ** to the list type, then this line:
push(&start, 10);
would look more like
push(start, 10);
but start wouldn't have changed within that scope so subsequent calls to the push functions wouldn't be doing anything. Your PrintList function doesn't care since it doesn't care to make changes to start and have those changes be reflected in code outside of the function's scope
@coral sundial @long raft @orchid needle thanks for the replies bois it had been a while since I wrote some c language but I get it now thanks to all of you
@coral sundial you should totally put your code in repositories. You can rollback code in case you screw up or need an earlier version and you can easily share and collaborate with others. Also if you're doing a lot of these hobby projects the repositories can serve as your portfolio.
good to start now imo ๐
fortunately I dont ever want to be a software engineer xD
being a software engineer requires a god complex with a side of being fucked in the head a bit
fortunately i have both
And you think you will never have to program in in mechatronics? Ha!
ngl I often forget the correct syntax and use the syntax error to constantly remind me
print('Hello world')
Or Google. Google works too.```cs
Console.WriteLine('Hello world')
#this code color thing is kinda cool but also a tad limited
isnt python syntax pretty straightforward?
mechatronics is dope
idk what other professions do on the job but I can imagine that you may need to do C
mmm somebody must have wrote some c#, my derp sense is tingling
@coral sundial yeah, that would work in Py without the slash
