Got 100% on my assembly project when all I did was essentially a bunch of if-thens for every possible condition in the project. I emailed my professor saying my code was shit and how I would have improved it if I could do it again.
It feels wrong getting 100% for bad code, but whatever
[QUOTE=proboardslol;50028374]Got 100% on my assembly project when all I did was essentially a bunch of if-thens for every possible condition in the project. I emailed my professor saying my code was shit and how I would have improved it if I could do it again.
It feels wrong getting 100% for bad code, but whatever[/QUOTE]
Really depends upon the specification of the assignment. Good that you improved it later -- but if it was an assignment on conditional branching, then why optimise? You will probably be tested in the other things later.
I'm not saying you shouldn't do you best, but I am sure the code you submitted could be further optimised by someone much more proficient. So you need to have some sort of threshold.
And please, let us see the difference in code from the two -- that would make it more educational for us, as well as it has been for you :-)
[QUOTE=mikkeljuhl;50028569]Really depends upon the specification of the assignment. Good that you improved it later -- but if it was an assignment on conditional branching, then why optimise? You will probably be tested in the other things later.
I'm not saying you shouldn't do you best, but I am sure the code you submitted could be further optimised by someone much more proficient. So you need to have some sort of threshold.
And please, let us see the difference in code from the two -- that would make it more educational for us, as well as it has been for you :-)[/QUOTE]
The assignment was to make a "bot", which had different states and changed those states based on an event input by the user. The test was to make sure we understood assembly (not even real assembly, just the barebones Marie assembly with like 12 instructions), so it was fine that I did it as shittily as possible (she actually commended me for not emailing her asking for a hint like apparently the rest of my class did), but I know that I can do better.
I didn't actually finish the improvements, since I'm not being graded on it, I just described how I would have designed it better in the future.
The specification is here:
[img]http://i.imgur.com/KY87Uyo.png[/img]
If I enter in invalid event, it just ignores it and asks for input again
Code I submitted:
[code] Load State
Output
Loop, Jump ChZ /Main loop, load each state and act accordingly
Asleep, Load State /Load the state after each check just to be sure
Jump ChS /Check if state is S (Spawn)
Aspawn, Load State
Jump ChW /Check if state is W (Wander)
Awand, Load State
Jump ChA /Check if state is A (Attack)
AAtc, Load State
Jump ChD /Assumes that state is D if not any other state
EndCh, Load State
Jump Loop /Loop infinitely
ChZ, Subt Z /Check Z
Skipcond 400
Jump ZNotZ /ZNotZ is check for Deep sleep
Jump SDS
ZNotZ, Skipcond 800 /Check Zz in the same subroutine
Jump Asleep /Jump to "After Sleep Check"
Jump SW /Zz is the only state greater than Z, so set to Wander
ChS, Subt S /Check Spawn
Skipcond 400
Jump Aspawn /Jump back to checking loop
SpGetI, Input
Subt N /State is S, get Input, check for N
Skipcond 400
Jump SpNotN /Input Not N
Jump SW /Set to wander if input is N
SpNotN, Subt Four /Check if Input is R
Skipcond 400
Jump SpGetI /Input not R; input invalid; get new input
Jump SA /Set to Attack
ChW, Subt W /Check Wander
Skipcond 400
Jump Awand /Not Wander, go back to chck loop
WGetI, Input /State is wander, get Input
Subt N /Check if input is N
Skipcond 400
Jump WNotN /Not N
Jump SD /Input N, set to Drowsy
WNotN, Subt Four /Check if input is R
Skipcond 400
Jump WGetI /Not R; input invalid; get new input
Jump SA /Input is r; set to attack
ChA, Subt A /Check Attack
Skipcond 400
Jump AAtc /Not A, go back to check loop
AGetI, Input /State is A, get input
Subt K /Check if input is K
Skipcond 400
Jump AtNotK /Input is not K
Jump SS /Input is K, set state to spawn
AtNotK, Subt Three /Check if input is N
Skipcond 400
Jump AtNotN /Input Not N
Jump SW /Input is N, set state to wander
AtNotN, Subt Four /Check if input is R
Skipcond 400
Jump AGetI /Input not R; input invalid; get new input
Jump SA /Input is R; Set state to A
ChD, Input /Check Drowsy; assume it is
/Since all other states have been checked
Subt N /Check if state is N
Skipcond 400
Jump DrNotN /Input is not N
Jump SZ /Input is N, go to sleep
DrNotN, Subt Four /Check if Input is R
Skipcond 400
Jump ChD /Input is not R; invalid input; get new input
Jump SA /Input is R, set state to Attack
SZ, Clear /Set State to Lightsleep
Add Z
Output
Store State
Jump EndCh
SDS, Clear /Set State to Deep Sleep
Add Z
Output
Add One
Store State
Jump EndCh
SW, Clear /Set State to Wander
Add W
Output
Store State
Jump EndCh
SA, Clear /Set State to attack
Add A
Output
Store State
Jump EndCh
SS, Clear /Set State to Spawn
Add S
Output
Store State
Jump EndCh
SD, Clear /Set State to Drowsy
Add D
Output
Store State
Jump EndCh
State, Hex 53 /variables and constants
S, Hex 53 /States
A, Hex 41
W, Hex 57
D, Hex 44
Z, Hex 5A
Zz, Hex 5B /Deep sleep; Z+1 in ascii; subtract one to print Z
N, Hex 4E /Events
R, Hex 52
K, Hex 4B
One, Hex 1
Three, Hex 3
Four, Hex 4 /Commonly used when Subtracting N from R[/code]
What I emailed her:
[quote]Prof. [redacted],
Regarding project 1B, you commented that it was notable that I did the project independently, without needing a hint. While I'm proud of the fact that I was able to figure out Marie pretty simply (seeing as it has a very limited instruction set), I'm sure I don't need to tell you that what I did was essentially enumerating every possible if statement and creating non-abstract subroutines for every single case. In other words, I committed a mistake that I haven't done since I was 13: I made the program an endless list of if-then statements for every possible scenario.
I did not use any of the "indirect" instructions, meaning that had I spent more time studying the instruction set and examples given to us, I might have condensed the length of the code and use more abstract principles of design. Some thoughts I had on the situation:
1. I could have made 1 "set" function, in which the state to be set would be referenced by a "toSet" pointer, which would point to a new state before "set" would be called.
2. I could have made "toSet" values. Since There are only 3 events that can be triggered, and only a handful of responses from those triggers (set new state, get new input/ignore event), Each "toSet" (rCallback, nCallback, kCallback) might have simply been associated with a control code, where a control code of 0 would signify ignoring that input/getting new input (in the case of a k-event in a w-state) and every other control code would be the new state to be set. The code may look something like this:
[code]CheckState, Load State /Check Each state
Subt S
skipcond 400
Jump CheckW
Jump Sconds /Sconds sets an array of callbacks to specific values depending on the rules of each state
CheckW, Load State
Subt W
skipcond 400
Jump CheckA
Jump Wconds
/... etc, for all states A, D, Z, Zz
Sconds, Load Rcallback
Clear
Add A
Store Rcallback
Load Ncallback
Clear
Add W
Store Ncallback
Load Kcallback
Clear
Store Kcallback
Jump CheckEvent
/...etc, for all states W, A, D, Z, Zz
CheckEvent, Load Event /event has already been entered
Subt R
skipcond 400
Jump CheckN /Not R, check N
Load Rcallback
Store toSet /Set the new state to the Rcallback, which has been set by the state conditions
Jump Set
CheckN, Load Event
Subt N
skipcond 400
Jump CheckK /Not N, check K
Load Ncallback
Store toSet /Set the new state to the Ncallback, which has been set by the state conditions
Jump Set
CheckK, Load Event
Subt K
skipcond 400
Jump getInput /Input not recognized, go get a new input and try again
Load Kcallback
Store toSet /Set the new state to the Kcallback, which has been set by the state conditions
Jump Set
Set, Load toSet /set new state and output it
skipcond 400
Jump EventOk /Event != 0, so event is ok
Jump getInput /Event == 0, so ignore input and get new input
EventOk, Store State
Output
Jump Checkstate /Jump back to check the state
Rcallback, Hex 0
Ncallback, Hex 0
Kcallback, Hex 0
S, Hex 53
/Hex values for each State, etc.
K, Hex 4B
/Hex values for each event, etc.
toSet, Hex 0
[/code]
Obviously, this is incomplete, but I think you understand the Idea. This solution still requires no pointers, but I imagine there are a few ways to condense the code even further by using pointers (pointer arithmetic to point to specific conditions or callbacks without having to name them, knowing that they are in a specific place next to one-another, but this may just complicate the code further).
Specific conditions can be set in each instruction for Z and Zz, perhaps a specific control code (-1, or 1, perhaps) which will tell the checkEvent subroutine to skip input and go straight to setting, and then further conditions after that
I think that this is a much more abstract way to go about the assignment, but I was wondering what your input on the subject would be:
1. Is abstraction necessarily a good thing in low level programming like assembly, or does it further complicate the assignment and therefore execution time?
2. Are there principles for low level programming that don't apply to higher level programming languages like C?
Thanks for your time,
Collin Oswalt[/quote]
[quote][vid]http://wyattmarks.com/screenshots/2016_03-29_06:19.webm[/vid][/quote]
I added networking. Currently chat works, and I just got the level to send over the network. Fuck yeah!
Giving a presentation about my modem ([url]https://github.com/collinoswalt/modem/[/url]) program at my community college. no longer than 8 minutes and I'm going to do an in-person demonstration of it (bringing two laptops to demonstrate that I didn't just copy paste the file). I'm also reading Shannon's [I]Mathematical Theory of Communication[/I] to give some mathematical filler and describe the principles going on in the program as well as a bit of math (bitrate, margin of error, etc.)
This is what happens when you accidentally draw a sunburst with >1500 arms. Not quite my intention.
[img]http://i.imgur.com/0QkZ0By.png[/img]
So I've been on a bit of rampage cleaning up my WebGL Prototyping Framework Thing™ and generally just improving the hell out of it after months of not really having much time nor energy to properly gamedev.
Tonight (6AM now, no going back), I tackled the text system that I've somehow made myself put up with through [i]two or three tri-annual Ludum Dares.[/i] Conceptually, it was sound, but man was it lacking in...everything. It's still very frame-dependent, no where near what I want it to eventually be yet, but it will serve my purposes much better for the near future.
Long story short, I've fully redrawn the font, refined and optimised (not fully, yet) the management system, fixed a lot of schtuff in my renderer surrounding textures and added capabilities to colour, rotate, scale, and linebreak any text you send to the back-end for rendering.
It might not look very impressive as-is, especially in comparison to what I could be achieving had I not ignored this for months, but here's a full font print-out. After one design pass, I'm pretty happy with how it looks, though some of those punctuation characters will have to change a bit I think.
[IMG]https://dl.dropboxusercontent.com/u/38489921/Shared/totalfon.PNG[/IMG]
I made EncryptedInt class (and soon float and double). It is in memory encrypted number. It consists of three encrypted numbers and three keys. If you modify one of the encrypted numbers, there is no damage, since others 2 numbers are still same (when decrypted).
Should I upload it to github, any interest?
[code]
using System;
using System.Collections;
[Serializable]
public struct EncryptedInt {
//XOR encryption
static System.Random random;
static EncryptedInt() {
random = new System.Random(System.DateTime.UtcNow.Millisecond);
}
int _encryptedA;
int _encryptedB;
int _encryptedC;
int _keyA;
int _keyB;
int _keyC;
public EncryptedInt(int value) {
_keyA = random.Next(int.MinValue, int.MaxValue);
_keyB = random.Next(int.MinValue, int.MaxValue);
_keyC = random.Next(int.MinValue, int.MaxValue);
_encryptedA = value ^ _keyA; //XOR encrypt
_encryptedB = value ^ _keyB;
_encryptedC = value ^ _keyC;
}
public int Value {
get {
//temporary variables
int _a = _encryptedA ^ _keyA; //XOR encrypt
int _b = _encryptedB ^ _keyB;
int _c = _encryptedC ^ _keyC;
if (_a == _b && _b == _c)
return _a;
// something got modified, just find most common number, if all 3 different, then crash
if (_a == _b) {
Value = _a;
return _b;
}
else if(_a == _c) {
Value = _c;
return _c;
}
else if (_b == _c) {
Value = _c;
return _c;
}
else {
throw new ArgumentException("Memory error"); //all 3 variables are different
}
}
set {
_encryptedA = value ^ _keyA;
_encryptedB = value ^ _keyB;
_encryptedC = value ^ _keyC;
}
}
}
[/code]
[editline]30th March 2016[/editline]
Btw, the point of this is to prevent in-memory hacking with help of Android apps.
[QUOTE=Fourier;50032152]I made EncryptedInt class (and soon float and double). It is in memory encrypted number. It consists of three encrypted numbers and three keys. If you modify one of the encrypted numbers, there is no damage, since others 2 numbers are still same (when decrypted).
Should I upload it to github, any interest?
[code]
using System;
using System.Collections;
[Serializable]
public struct EncryptedInt {
//XOR encryption
static System.Random random;
static EncryptedInt() {
random = new System.Random(System.DateTime.UtcNow.Millisecond);
}
int _encryptedA;
int _encryptedB;
int _encryptedC;
int _keyA;
int _keyB;
int _keyC;
public EncryptedInt(int value) {
_keyA = random.Next(int.MinValue, int.MaxValue);
_keyB = random.Next(int.MinValue, int.MaxValue);
_keyC = random.Next(int.MinValue, int.MaxValue);
_encryptedA = value ^ _keyA; //XOR encrypt
_encryptedB = value ^ _keyB;
_encryptedC = value ^ _keyC;
}
public int Value {
get {
//temporary variables
int _a = _encryptedA ^ _keyA; //XOR encrypt
int _b = _encryptedB ^ _keyB;
int _c = _encryptedC ^ _keyC;
if (_a == _b && _b == _c)
return _a;
// something got modified, just find most common number, if all 3 different, then crash
if (_a == _b) {
Value = _a;
return _b;
}
else if(_a == _c) {
Value = _c;
return _c;
}
else if (_b == _c) {
Value = _c;
return _c;
}
else {
throw new ArgumentException("Memory error"); //all 3 variables are different
}
}
set {
_encryptedA = value ^ _keyA;
_encryptedB = value ^ _keyB;
_encryptedC = value ^ _keyC;
}
}
}
[/code]
[editline]30th March 2016[/editline]
Btw, the point of this is to prevent in-memory hacking with help of Android apps.[/QUOTE]
On my paper, I think it would work if you had a struct type or a class where values are stored as objects, usually typedef-ed together a pointer or some sort of a reference, that move to an different memory region or address every time its' value(s) is (are) changed through overridden operators (allocate a new object storing the values then replace the older one) and 'new'. Usually helps against scriptkiddies who don't bother digging inside the assembly.
On a second thought, the only flaw is the pointer that points to said ever-changing object.
[QUOTE=Dromlexer;50032422]On my paper, I think it would work if you had a struct type or a class where values are stored as objects, usually typedef-ed together a pointer or some sort of a reference, that move to an different memory region or address every time its' value(s) is (are) changed through overridden operators (allocate a new object storing the values then replace the older one) and 'new'. Usually helps against scriptkiddies who don't bother digging inside the assembly.
On a second thought, the only flaw is the pointer that points to said ever-changing object.[/QUOTE]
I see what you mean, if it detects modification, change the location of those 3 numbers with new operator. It is indeed a lot more secure but with lots of 'new' operators it can be also GC intense and slower. This is why I don't even use arrays and have pre-named variables, it's faster and doesn't touch GC.
Mine is enough secure anyway - you need to get locations of those variables first and you need to know it's XOR encryption. It's enough to fuck with noob/advanced script kiddies.
Though, if hacker will decompile assembly and look at those classes then he will get some idea how it works.
cartman300, any comments about this?
Made some progress. Key spawn locations can now be defined from within the program in an interactive manner. I know that not being able to see previously set keys seems a bit silly at first, but this is ultimately supposed to be projected onto a real keyboard. That way you can clearly see where your key is supposed to go to.
[media]https://www.youtube.com/watch?v=PLKhjf_Uiow[/media]
[QUOTE=Dromlexer;50032422]
quote
[/QUOTE]
Oh and another method would be additional checksum so you can know when value got corrupt.
My friend and I are working on a Tetris clone for our final project:
[img]http://i.imgur.com/HHW0nv9.png[/img]
[img]http://i.imgur.com/9BA1Zos.png[/img]
Found time to work a little on Half-Payne, made a diving move which is basically the same as long jump module but allows to jump in any direction, it turns slowmo automatically until you land.
The slowmo charge is now exhaustable and it was a pain to setup HUD for it (though the whole HUD rendering pipeline seems logical now and just requires getting used to). [sp]can't wait to fuck my ass with sprite rendering of hourglass[/sp]
[vid]http://webm.land/media/tJgT.webm[/vid]
whoever was making that parkour racing game, i'm borrowing that idea for my uni project.
we were given the restraint of either making a fps game or a racing game so i took the opportunity to make both in one.
[QUOTE=Pat.Lithium;50033276]whoever was making that parkour racing game, i'm borrowing that idea for my uni project.
we were given the restraint of either making a fps game or a racing game so i took the opportunity to make both in one.[/QUOTE]
holy shit do you mean it's something like Mirror's Edge time trials?
[QUOTE=Pat.Lithium;50033276]whoever was making that parkour racing game, i'm borrowing that idea for my uni project.
we were given the restraint of either making a fps game or a racing game so i took the opportunity to make both in one.[/QUOTE]
ah dude, that's sweet! here's a tip: never do networking. EVER. keep it splitscreen to avoid any headaches.
[QUOTE=suXin;50033506]holy shit do you mean it's something like Mirror's Edge time trials?[/QUOTE]
haha, that's pretty much exactly what it is. Speaking of which, since I haven't posted in awhile, here's some new gameplay stuff
[vid]https://dl.dropboxusercontent.com/u/1400138/2016-03-30-1054-57.mp4[/vid]
[QUOTE=Gamerman12;50033546]haha, that's pretty much exactly what it is. Speaking of which, since I haven't posted in awhile, here's some new gameplay stuff[/QUOTE]
It's just that long time ago I had an idea that someone would make a Trackmania style game but on foot, with level editor ofcourse (you still can make something worthy just with rectangular blocks). People would run around and compete on some kind of leaderboards and also share their levels, I believe the whole thing could really shoot with enough effort.
In case anyone was wondering about the followup to the email I sent to my professor::
[Quote]You are addressing the problem of "trade-offs". Obviously, given a simple finite-state-automata (fsa) like the bot without any description of its use, you could implement a prototype any way you want. If you are given more context, then one implementation might be better than another.
As for your questions:
(Rephrased) If a solution is an endless list of if-then-else statements, is it bad?
Not necessarily. I can name at least 2 domains where this approach is "the way". One domain is decision tree construction of the expert system. Another is the compiler. This approach may be tedious for human, but absolutely good for automation.
(Rephrased) Is it better to condense code with high-level constructs?
Again, it depends on your purpose. If the code is for human reading (such as the hint I gave), then it's necessary to make it as intuitive as possible to humans. But what is intuitive to human is not necessarily intuitive to computers.
The hint for the bot is designed from the theoretical perspective of the fsa. It can be customized for binary state values thus maximizing orthogonality and state+signal transition. Your proposed design in this email is going in a similar direction. However, not all problems have neat solutions like that. Most real-world problems are less systematic.
In today's computer science, people really like the idea of modularity and divide-and-conquer. Low-level programming is for achieving high performance of simple algorithms. You will find a lot of insight to your question regarding principles of low-level vs high-level programming in this week's homework regarding sorting or not sorting an array.[/quote]
Can someone explain what she meant by orthoganality?
[QUOTE=Gamerman12;50033546]
haha, that's pretty much exactly what it is. Speaking of which, since I haven't posted in awhile, here's some new gameplay stuff[/QUOTE]
That looks super fun, please tell me you aren't going to keep it to local multiplayer
[QUOTE=LordOfGears2;50034026]That looks super fun, please tell me you aren't going to keep it to local multiplayer[/QUOTE]
nope, it's local, networked, and both at the same time if you choose.
[QUOTE=proboardslol;50033970]In case anyone was wondering about the followup to the email I sent to my professor::
Can someone explain what she meant by orthoganality?[/QUOTE]
she sounds sexy af
[QUOTE=Downsider;50035611]she sounds sexy af[/QUOTE]
She's a very nice woman
[QUOTE=proboardslol;50033970]In case anyone was wondering about the followup to the email I sent to my professor::
-snip-
Can someone explain what she meant by orthoganality?[/QUOTE]
I'm no CS major, so I may be wrong about the context:
For 3D space, orthogonal means at a 90 degree angle to the two other reference dimensions. Like a 3D normal to a plane.
A 3D vector is defined by the three values along the three dimensions. This is because the value along one dimension could not be represented with any values in the other two dimensions as they are independent by definition.
I think she meant non-interconnectivity. Unrelatedness.
In statistics, orthogonal means also independent.
[quote]
...
The hint for the bot is designed from the theoretical perspective of the fsa. It can be customized for binary state values thus increasing independence and state+signal transition.
...
[/quote]
[img]http://www.carp.tk/~anon/files/1459398116.png[/img]
Placing objects in unmanaged memory.
[editline]31st March 2016[/editline]
Changing the value of Int after allocation crashes the runtime because it protects it somehow and detects corruption after i overwrite it.
Had a tiring day so I made this when I got home! It took a few hours. Not perfect obviously but :tired:
[vid]https://d1wst0behutosd.cloudfront.net/videos/8431751/22255367.480p.mp4?Expires=1459463361&Signature=VnP5B3RYVOCe3Uh5MUHaDCZLwPoEqX4E3~53rrmgvPHi8Dnihs1OWoDilQp9H7oypYyInWO117yaTPCtJuoAi4j4EezAAKh50gtxh9B9BNQFalGhoOVsjg-jyolnm5AMI5agN6TkX55aldyAnLYRI3KtGSmjiNvlRHMFwc6xHRDSAmEBty30iq0~AU6Nw5DJIkQ6yilrIoo-x4kL4u~tasDEeK-EM3q0NL1MxDFcjmZXe4U0bJHbaNOS5fjp9Ooq5h8ttYO6pwzz3VHLwdy03AIw5v2gP7elg~LP6PaTkTTpZPJlx9Ve1Gp~7Rh7ZdAIxx8vMtbE9BYHHWLA2QClvA__&Key-Pair-Id=APKAJJ6WELAPEP47UKWQ[/vid]
Orthogonality is just that dot product between two vectors/functions is 0. <a,b> = 0.
It has lots of implication, as others mentioned
- right angle
- independence
- transforms are made out of orthogonal vectors/functions,
Orthogonal functions/vectors are very easy to work with, because you know they are independent.
Bounded functions are just vectors with infinite dimension. Also bounded 2D functions are just matrices with infinite dimension. Let that sink in, to me it was mind blowing.
Now, matrices can be orthogonal between each other too (dot product between two matrices).
You have orthogonal functions in digital signal processing, machine vision, statistics etc... I can go on but I need to work.
proboardslol, maybe she meant this:
In math, you can have kernels. Those are predefined objects, let it be vector or matrix. You use those to filter bigger vectors/matrices. For example gaussian blur uses gaussian kernel.
Imagine those kernel as sensors. If you have more of those "sensors", and if they are orthogonal, you know that which one senses something, it doesn't affect other sensors. (this is why they are easy to work with).
Don't know what you want to sense in robot though. 3D space? temperature? have no clue.
[QUOTE=Matthew0505;50034133]You might want to take a look at KeePass's source code, it's a C# program with in-memory protection.[/QUOTE]
Will do.
[QUOTE=Doritos_Man;50033090]My friend and I are working on a Tetris clone for our final project:
[img]http://i.imgur.com/HHW0nv9.png[/img]
[img]http://i.imgur.com/9BA1Zos.png[/img][/QUOTE]
Planning on releasing it even as an exe?
Sorry, you need to Log In to post a reply to this thread.