A simple miner program

Game development specific discussions.
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Re: A simple miner program

Postby BasicCoder2 » Apr 05, 2020 22:02

@badidea

I thought OOP was to prevent modifications breaking the code? My coding is rather simple much as I coded on the old machines like the c64. I try and break it down into modules that only do one thing.

The reason I deleted the post was it was rubbish (I thought) and I wasn't happy with the coding. As for the game play it was only a appetiser for better things :) The other factor was collecting the diamonds with the least amount of drilling and ladder building which required some strategy thinking. Of course I would be adding other stuff and that is why I decided to rewrite the "engine" part to make it easier to add other things like rolling or falling rocks and other character sprites apart from the miner.

So until the corona virus gets me I will be concentrating on this particular project and hopefully have something to offer for comment or suggestions without feeling the need to delete it :)
badidea
Posts: 2007
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: A simple miner program

Postby badidea » Apr 05, 2020 22:23

BasicCoder2 wrote:I thought OOP was to prevent modifications breaking the code?

I don't know. Maybe if you are good at it. And if you are capable of doing the full design before actual coding. Which I cannot.
Maybe for a next project I try without OOP and see what happens. But with 'structs', else I go crazy. Maybe play with namespaces as well to keeps things ordered.

But the problem is not related to OOP. I use a state (waling, climbing, falling, idle, etc) for the miner. Currently I switch to that states without doing all the checks if that state is allowed. I save the previous state and it (later on in the code) turns out that state is not allowed, I switch back to the previous state. That is a bit weird I think. So I would probably implement a requested state and only switch to that state if allowed.

BTW, any code can break by modification. It is very easy. Change 1 single bit and the changes are high the the program does not work any more. Unlike humans which can handle a bit of modification usually, up to a certain level, without completely crashing.
dodicat
Posts: 6390
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: A simple miner program

Postby dodicat » Apr 06, 2020 11:24

Just for fun, using some oop but bypassing it back to procedural.

Code: Select all


Enum
    up
    down
End Enum

type strings
    private:
    as string original
    as string sorted
    declare operator cast() as string
    as byte direction
    declare constructor(as string, as byte,as long,as long)
    declare sub sort(as strings,as long,as long)
end type

operator strings.cast() as string
print "Original string: "; original
print "Sorted string:   ";sorted
print "Press any key . . ."
return ""
end operator

constructor strings(tosort as string, dirn as byte,l as long,u as long)
original=tosort
sorted=tosort
direction=dirn
sort(this,l,u)
swap sorted,original
end constructor

sub strings.sort(s As strings,begin As Long,Finish As Long)
    Dim As Long i=begin,j=finish
    Dim As ubyte x =S.original[(I+J)\2]
    While  I <= J
    if direction=down then
        While S.original[I] > X:I+=1:Wend
        While S.original[J] < X:J-=1:Wend
    else
        While S.original[I] < X:I+=1:Wend
        While S.original[J] > X:J-=1:Wend
    end if
    If I<=J Then Swap S.original[I],S.original[J]: I+=1:J-=1
    wend
    If J > begin Then sort(S,begin,J)
    If I < Finish Then sort(S,I,Finish)
End sub
'=============================

'get the actual procedures
declare function show alias "_ZN7STRINGScv8FBSTRINGEv"(as strings) as string  'cast()
declare sub construct cdecl alias "_ZN7STRINGSC1ER8FBSTRINGaii"(as strings,as string,as byte,as long,as long)'constructor

dim as string f="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"

dim as strings ptr result=callocate(sizeof(strings))

construct(*result,f,down,0,len(f)-1)

show (*result)

deallocate result


sleep


 
 
badidea
Posts: 2007
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: A simple miner program

Postby badidea » Apr 06, 2020 12:37

dodicat wrote:Just for fun, using some oop but bypassing it back to procedural.
...

That code is not funny :-P
dodicat
Posts: 6390
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: A simple miner program

Postby dodicat » Apr 06, 2020 13:14

In Linux 32 bit
the constructor alias is "_ZN7STRINGSC1ER8FBSTRINGall"
Don't have 64 bit Linux to test.
You seem in a very bad mood badidea.
BasicCoder2
Posts: 3525
Joined: Jan 01, 2009 7:03

Games and OOP

Postby BasicCoder2 » Apr 06, 2020 20:11

@badidea
badidea wrote:
BasicCoder2 wrote:I thought OOP was to prevent modifications breaking the code?

I don't know. Maybe if you are good at it. And if you are capable of doing the full design before actual coding. Which I cannot.
Maybe for a next project I try without OOP and see what happens. But with 'structs', else I go crazy. Maybe play with namespaces as well to keeps things ordered.

It is not so much I have a problem with classes, which I did learn about when I was programming in C++ using the Dev-C++ compiler, it is just that when I changed to FreeBasic over 10 years ago it didn't support OOP and I kind of forgot about it. I think the enthusiasts for OOP with FreeBASIC are already well practised using it with c++

Oop does however seem well suited for games which are essentially a collection of interacting objects.

BTW, any code can break by modification. It is very easy. Change 1 single bit and the changes are high the the program does not work any more. Unlike humans which can handle a bit of modification usually, up to a certain level, without completely crashing.


Indeed humans and other living things are examples of a hierarchy of self contained modules as indeed is the whole biosphere. And that collection of processing modules we call the brain uses statistical decision making not hard brittle logic although it is capable of doing logic when required.
badidea
Posts: 2007
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: A simple miner program

Postby badidea » Apr 06, 2020 21:17

dodicat wrote:In Linux 32 bit
the constructor alias is "_ZN7STRINGSC1ER8FBSTRINGall"
Don't have 64 bit Linux to test.

Strange, "_ZN7STRINGSC1ER8FBSTRINGaii" works fine here on linux fbc 32 and 64 bit.

dodicat wrote:You seem in a very bad mood badidea.

Than I must be me with the corona-depression. Maybe I did too many simulations.
dodicat
Posts: 6390
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: A simple miner program

Postby dodicat » Apr 06, 2020 22:17

I was experimenting with things like calling a constructor for example by using alias "_ZN7STRINGSC1ER8FBSTRINGall", in order to overcome the C++ class problem.
It is ugly, but my reasoning is that basically C and C++ (and FreeBASIC) are procedural languages, OOP is just a layer over the basic procedures.
I was hoping to get away with using a type structure and accessing C++ class methods via these names, for the more straightforward dynamic libraries anyway.

Return to “Game Dev”

Who is online

Users browsing this forum: No registered users and 2 guests