Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - rain_storm

Pages: 1 [2] 3 4 5
Yabasic / AI Tidy Up Teamwork
« on: July 15, 2009 »
This code uses fuzzy logic to determine which critter is in the best position to solve the problem the other critters will not compete and wont get in the way. The problem they face is getting the ball (yellow circle) into the goal (Red circle) you can move the ball any where in the legal area the critters will always clean up after you.

Code: [Select]
// ======================================= //
// AI : Team work                          //
// --------------------------------------- //
// The problem :                           //
// A team of bots must work together to    //
// put the ball in the goal                //
// --------------------------------------- //
// Progress towards the solution is graded //
// by first distance between ball and goal //
// second distance between AI bot and ball //
// Third whether bot can see ball and goal //
// ======================================= //
debug = 0
open window 640, 512
window origin "cc"

UP = 16
DN = 64
LF = 128
RT = 32
LZ = 4096
RZ = 8192

bots = 3 // bot 0 is the ball
dim PosX(bots) // position x
dim PosY(bots) // position y
dim RotZ(bots) // rotation
dim DirX(bots) // lateral direction
dim DirY(bots) // foward direction
dim Radi(bots) // Radius
dim Ctrl(bots) // control flags

dim SeeBall(bots)
dim SeeGoal(bots)
dim NearBall(bots)
dim Solved(bots)

BestProgress = 640

label Init
    // The environment
    x1 = -220.0
    y1 = -220.0
    x2 =  220.0
    y2 =  220.0
    x3 = -200.0+50.0
    y3 = -200.0+50.0
    x4 =  200.0-50.0
    y4 =  200.0-50.0
    // The goal
    GoalX = 0.00
    GoalY = 0.00
    GoalR = 30.0
    // the problem
    PosX(0) = -100.0
    PosY(0) = -100.0
    RotZ(0) =  pi*3/2
    Radi(0) =  10.00

    // The AI bots
    for b = 1 to bots
        Ctrl(b) = 0
        Radi(b) = 30.0
        DirX(b) = 0.0
        DirY(b) = 0.0
        RotZ(b) = ran(pi) - ran(pi)
0       PosX(b) = ran(200.0-Radi) - ran(200.0-Radi)
        PosY(b) = ran(200.0-Radi) - ran(200.0-Radi)
        for a = 0 to bots
            if (a <> b) then
                adj = PosX(a) - PosX(b)
                opp = PosY(a) - PosY(b)
                hyp = sqrt(adj*adj + opp*opp)
                if (hyp < Radi(a) + Radi(b)) goto 0
        next a
    next b
    bot = 1
label Main
    gosub Goal
    gosub AI
    gosub Control
    gosub Draw
    //wait 0.002
    goto Main

label Goal
    adj = PosX(0) - GoalX
    opp = PosY(0) - GoalY
    LastProgress = Progress
    Progress = sqrt(adj*adj + opp*opp)
    if (Progress < BestProgress) BestProgress = Progress

label AI
    Ctrl(0) = peek("port1")
    if (Progress <= 10.0) then
        // Success
        for b = 1 to bots
            adj = PosX(b) - PosX(0)
            opp = PosY(b) - PosY(0)
            hyp = sqrt(adj*adj + opp*opp)
            if (hyp < 3.0*Radi(b)) then
                // Move away from ball
                Ctrl(b) = DN
                // Stay away from ball
                Ctrl(b) = 0
        next b
        Winner = 0
        Solution = 1000
        // Reset progress towards solution
        for b = 1 to bots
            Ctrl(b) = 0
            // Viewing angle of ball
            px = PosX(b)
            py = PosY(b)
            tx = PosX(0)
            ty = PosY(0)
            vx = cos(RotZ(b)) + PosX(b)
            vy = sin(RotZ(b)) + PosY(b)
            SeeBall(b) = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
            // Viewing angle of goal
            vx = cos(RotZ(b)) + PosX(b)
            vy = sin(RotZ(b)) + PosY(b)
            SeeGoal(b) = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
            // Distance to ball
            adj = PosX(b) - PosX(0)
            opp = PosY(b) - PosY(0)
            NearBall(b) = sqrt(adj*adj + opp*opp)
            adj = PosX(b) - GoalX
            opp = PosY(b) - GoalY
            NearBall(b) = NearBall(b)/sqrt(adj*adj + opp*opp)
            // Calculate which bot is closest to the solution
            Solved(b) = (NearBall(b)*SeeGoal(b))/SeeBall(b)
            if (Solved(b) < Solution) then
                Solution = Solved(b)
                Winner = b
        next b
    for b = 1 to bots
        // Look at ball using Crossproduct
        px = PosX(b)
        py = PosY(b)
        tx = PosX(0)
        ty = PosY(0)
        vx = cos(RotZ(b)+pi/4) + PosX(b)
        vy = sin(RotZ(b)+pi/4) + PosY(b)
        CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
        if (CP > 0.0) then
            vx = cos(RotZ(b)-pi/4) + PosX(b)
            vy = sin(RotZ(b)-pi/4) + PosY(b)
            CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
            if (CP < 0.0) then
                vx = cos(RotZ(b)) + PosX(b)
                vy = sin(RotZ(b)) + PosY(b)
                CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
                if (CP < 0.0) Ctrl(b) = Ctrl(b) + RZ
                if (CP > 0.0) Ctrl(b) = Ctrl(b) + LZ
                Ctrl(b) = Ctrl(b) + LZ
            Ctrl(b) = Ctrl(b) + RZ
        // Move towards ball using dot product
        adj = PosX(b) - PosX(0)
        opp = PosY(b) - PosY(0)
        hyp = sqrt(adj*adj + opp*opp)
        if (hyp > 8.0*Radi(b)) then
            vx = cos(RotZ(b)) + PosX(b)
            vy = sin(RotZ(b)) + PosY(b)
            DP1 = (vx-PosX(b))*adj + (vy-PosY(b))*opp
            vx = cos(RotZ(b)+pi) + PosX(b)
            vy = sin(RotZ(b)+pi) + PosY(b)
            DP2 = (vx-PosX(b))*adj + (vy-PosY(b))*opp
            if (abs(DP1) > abs(DP2)) then
                if (DP1 < 0.0) Ctrl(b) = Ctrl(b) + UP
                if (DP1 > 0.0) Ctrl(b) = Ctrl(b) + DN
                if (DP2 < 0.0) Ctrl(b) = Ctrl(b) + LF
                if (DP2 > 0.0) Ctrl(b) = Ctrl(b) + RT
            // Get the Goal in view using Crossproduct
            px = PosX(b)
            py = PosY(b)
            tx = GoalX
            ty = GoalY
            vx = cos(RotZ(b)+pi/4) + PosX(b)
            vy = sin(RotZ(b)+pi/4) + PosY(b)
            CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
            if (CP > 0.0) then
                vx = cos(RotZ(b)-pi/4) + PosX(b)
                vy = sin(RotZ(b)-pi/4) + PosY(b)
                CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
                if (CP < 0.0) then
                    if (Winner = b) then
                        vx = cos(RotZ(b)) + PosX(b)
                        vy = sin(RotZ(b)) + PosY(b)
                        CP = (vx-tx)*(py-ty) - (px-tx)*(vy-ty)
                        if (CP < 0.0) Ctrl(b) = Ctrl(b) + LF
                        if (CP > 0.0) Ctrl(b) = Ctrl(b) + RT
                        // Try to move the ball towards the goal
                        if (LastProgress > Progress) Ctrl(b) = Ctrl(b) + UP
                        if (LastProgress = Progress) Ctrl(b) = Ctrl(b) + UP
                        if (LastProgress < Progress) Ctrl(b) = Ctrl(b) + DN
                    if (Winner = b) Ctrl(b) = Ctrl(b) + RT
                if (Winner = b) Ctrl(b) = Ctrl(b) + LF
    next b

label Control
    for b = 0 to bots
        DirX(b) = 0.0
        DirY(b) = 0.0
        if (and(Ctrl(b), UP) = UP) DirY(b) = 0.5
        if (and(Ctrl(b), DN) = DN) DirY(b) =-0.5
        if (and(Ctrl(b), LF) = LF) DirX(b) =-0.5
        if (and(Ctrl(b), RT) = RT) DirX(b) = 0.5
        if (and(Ctrl(b), LZ) = LZ) RotZ(b) = RotZ(b) - pi/180.0
        if (and(Ctrl(b), RZ) = RZ) RotZ(b) = RotZ(b) + pi/180.0
        PosX(b) = PosX(b) + DirY(b)*cos(RotZ(b))
        PosY(b) = PosY(b) + DirY(b)*sin(RotZ(b))
        PosX(b) = PosX(b) + DirX(b)*cos(RotZ(b) + pi/2)
        PosY(b) = PosY(b) + DirX(b)*sin(RotZ(b) + pi/2)
    next b
    for b = 0 to bots
        for a = 0 to bots
            if (a <> b) then
                adj = PosX(b) - PosX(a)
                opp = PosY(b) - PosY(a)
                hyp = sqrt(adj*adj + opp*opp)
                if (hyp < Radi(a) + Radi(b)) then
                    cs = adj/hyp
                    sn = opp/hyp
                    Radi = (Radi(a) + Radi(b)) / 2
                    CenterX = (PosX(a) + PosX(b))/2
                    CenterY = (PosY(a) + PosY(b))/2
                    PosX(a) = CenterX - Radi*cs
                    PosY(a) = CenterY - Radi*sn
                    PosX(b) = CenterX + Radi*cs
                    PosY(b) = CenterY + Radi*sn
        next a
    next b
    for b = 1 to bots
        if (PosX(b) < x1 + Radi(b)) PosX(b) = x1 + Radi(b)
        if (PosY(b) < y1 + Radi(b)) PosY(b) = y1 + Radi(b)
        if (PosX(b) > x2 - Radi(b)) PosX(b) = x2 - Radi(b)
        if (PosY(b) > y2 - Radi(b)) PosY(b) = y2 - Radi(b)
    next b
    b = 0
    if (PosX(b) < x3 + Radi(b)) PosX(b) = x3 + Radi(b)
    if (PosY(b) < y3 + Radi(b)) PosY(b) = y3 + Radi(b)
    if (PosX(b) > x4 - Radi(b)) PosX(b) = x4 - Radi(b)
    if (PosY(b) > y4 - Radi(b)) PosY(b) = y4 - Radi(b)

label Draw
    setdispbuf draw
    draw = 1 - draw
    setdrawbuf draw
    clear window
    // The environment
    setrgb 1, 064, 128, 064
    fill box x1, y1 to x2, y2
    setrgb 1, 255, 255, 255
    box x3, y3 to x4, y4
    // The goal
    setrgb 1, 255, 064, 064
    fill circle GoalX, GoalY, GoalR
    setrgb 1, 128, 016, 016
    circle GoalX, GoalY, GoalR
    // The ball
    setrgb 1, 255, 255, 064
    fill circle PosX(0), PosY(0), Radi(0)
    setrgb 1, 064, 064, 004
    circle PosX(0), PosY(0), Radi(0)
    // The AI bots
    for b = 1 to bots
        cs = Radi(b)*cos(RotZ(b))
        sn = Radi(b)*sin(RotZ(b))
        setrgb 1, 064, 064, 128
        fill circle PosX(b), PosY(b), Radi(b)
        setrgb 1, 016, 016, 064
        line PosX(b), PosY(b) to PosX(b)+cs, PosY(b)+sn
        circle PosX(b), PosY(b), Radi(b)
        setrgb 1, 064, 064, 128
        fill circle PosX(b), PosY(b), 10
        setrgb 1, 016, 016, 064
        text PosX(b)-5, PosY(b)+3, str$(b)
    next b
    // Debug Reads Progress Data
    if (debug <> 0) then
        setrgb 1, 255, 255, 255
        text -300, -240, "Distance to Goal : " + str$(Progress)
        text -300, -220, "Best Distance is : " + str$(BestProgress)
        text  100, -240, "Solution : " + str$(Solution)
        text  100, -220, "Winner : " + str$(Winner)

ASM / Import by hash in Fasm
« on: March 28, 2009 »
Here a little something that I've been tipping away at for awhile now. Its 1kb opengl in fasm and I used import by hash to sidestep the import section, should work on all NT systems (Im using the PEB meathod for obtaining the base address of kernel32) . There is also a crinkler version that is compressed for comparison.

edit fixed code was missing ExitProcess,0 (using ret)

Code: [Select]
format MS COFF

 include ''
 include 'equates\'

 extrn '__imp__ExitProcess@4'       as ExitProcess:dword
 extrn '__imp__ShowCursor@4'        as ShowCursor:dword
 extrn '__imp__CreateWindowExA@48'  as CreateWindowExA:dword
 extrn '__imp__GetDC@4'             as GetDC:dword
 extrn '__imp__GetAsyncKeyState@4'  as GetAsyncKeyState:dword
 extrn '__imp__ChoosePixelFormat@8' as ChoosePixelFormat:dword
 extrn '__imp__SetPixelFormat@12'   as SetPixelFormat:dword
 extrn '__imp__SwapBuffers@4'       as SwapBuffers:dword
 extrn '__imp__wglCreateContext@4'  as wglCreateContext:dword
 extrn '__imp__wglMakeCurrent@8'    as wglMakeCurrent:dword
 extrn '__imp__glEnable@4'          as glEnable:dword
 extrn '__imp__glDepthFunc@4'       as glDepthFunc:dword
 extrn '__imp__glHint@8'            as glHint:dword
 extrn '__imp__glClear@4'           as glClear:dword
 extrn '__imp__glRotatef@16'        as glRotatef:dword
 extrn '__imp__glBegin@4'           as glBegin:dword
 extrn '__imp__glColor3f@12'        as glColor3f:dword
 extrn '__imp__glVertex3f@12'       as glVertex3f:dword
 extrn '__imp__glEnd@0'             as glEnd:dword

 public init
 init: xor     ebx, ebx
       invoke  ShowCursor, ebx
       invoke  CreateWindowExA, WS_EX_TOPMOST, szEdit, ebx, WS_POPUP+WS_VISIBLE+WS_MAXIMIZE, ebx, ebx, ebx, ebx, ebx, ebx, ebx, ebx
       invoke  GetDC, eax
       xchg    eax, ebp
       invoke  ChoosePixelFormat, ebp, pfd
       invoke  SetPixelFormat, ebp, eax, pfd
       invoke  wglCreateContext, ebp
       invoke  wglMakeCurrent, ebp, eax
       invoke  glEnable, GL_DEPTH_TEST
       invoke  glDepthFunc, GL_LEQUAL

 main: mov     ebx, 0.6
       invoke  glRotatef, ebx, ebx, ebx, ebx
       invoke  glBegin, GL_QUADS
       xor     ecx, ecx
       mov     esi, cube
       mov     cl, 0x18

 face: push    ecx
       xor     eax, eax
       mov     cl, 0x06

 vert: push    ebx
       mov     edx, eax
       shr     eax, 1
       and     dl, 0x01
       ror     edx, 1
       xor     [esp], edx
       loop    vert
       call    [glColor3f]
       call    [glVertex3f]
       pop     ecx
       loop    face
       invoke  glEnd
       invoke  SwapBuffers, ebp
       invoke  GetAsyncKeyState, VK_ESCAPE
       test    eax, eax
       jz      main
       invoke  ExitProcess, NULL

 szEdit db 'edit', 0
 cube:  ;  bgrzyx   bgrzyx   bgrzyx   bgrzyx
 face1  db 100111b, 110110b, 110100b, 100101b
 face2  db 110100b, 110110b, 011010b, 111000b
 face3  db 100101b, 110100b, 111000b, 001001b
 face4  db 001011b, 011010b, 111000b, 001001b
 face5  db 100101b, 100111b, 001011b, 001001b
 face6  db 100111b, 110110b, 011010b, 001011b


Edit - Reattached file

Useful links / Re: ASCII graphics examples
« on: August 27, 2008 »
These links might be of interest to you PO 256 byte games using console mode. Good for some inspiration. I think its great to see what can be done using only a charictor set instead of pixels.

Edit split topic instead of hijacking pixel's topic shouldve done that to begin with

General coding questions / Cheap Dithering?
« on: July 29, 2008 »
Anyone know how dithering works, cos I havent a clue. Of course this is for the compo so its extreme dithering I need with only 4 colours to choose from. Any body here that can explain how to match a colour to a 4 colour pallet

Yabasic / 256b StarFeild
« on: July 23, 2008 »
Hasnt been much activity on this board in awhile so I thought it was time to do something about that. This is a play on the minimum lines of source code theme that has been done before. This time the aim was to get a demo effect happening in no more than 256 bytes of source code. To start with I only did a simple paralax starfeild. The stars are coloured based on their distance. Tricks that have been used include -
  • using a colon ':' instead of a newline
  • using line numbers instead of labels
  • using single charictors instead of proper array / variable names
  • assigning a multi digit value to a variable (s=511) saves bytes if value is used often
tricks that couldnt be used this time -
  • not creating a newline for each label (works on the ps2 but breaks in the emulator)
  • using a data statement with a read statement can save bytes when many variables need to be declared
  • removing all comments (I have 6 bytes left over I used them for my signature)
  • removing clear screen and double buffering

well here is the source code unrolled for readability the attached file is crammed onto fewer lines to fit into the 256 byte limit
Code: [Select]
Open Window 1,1:
Dim x(s),y(s),z(s):
For a=0 To s:
0 setdispbuf d:
setDrawBuf d:
Clear Window:
For a=0 To s:
SetRGB 1,c,c,c:
Fill Circle x(a)*1.3,y(a),z(a):
Goto 0

Ive been reading 'Create your own website' by Michael Gray. When the book is talking about adding a contact href it states that printing your email address is very insecure. He mentions mailtoencryptor as a solution but when I go the there is no downloads. In fact theres nothing there but a link to the hosts webpage. Now at the moment I have my email address embedded in the html but I would prefer to have it encrypted and just put up a clickable png with the email written on it. Anyone use some software similar to mailtoencryptor?

General chat / Happy Birthday Slippy
« on: July 14, 2008 »
Happy Birthday buddy, heres to many more :cheers:

General coding questions / need info on LZ32.DLL
« on: July 13, 2008 »
Anyone know where I can find some information about this API? I am finding it very difficult to gather information myself. I have the masm inc file which tells me how many parameters each call requires, I have no info as to what these parameters are or how to use them for my own needs. I realise that there exist tools that already do this for you and that those tools do their job very well, still I want to learn how to do this myself.

General chat / memories of starting coding
« on: July 09, 2008 »
That other topic about new comers to programming has got me thinking about my own start. I thought we should have another topic for a discussion and share our own memories.

I was about 20-22 when I took another look at that demo disc that came with the PS2. Yabasic is on that disc. I ran it thinking it would be some sort of japanese game. I read the welcome message and ran the demos programs. there was a program in there that had a 3D bouncing ball, another had a cube, another one called mandelbrot, and a version of snake game. I had always wanted to make a video game as a young child but during my teens I had not given it any thought. funny that as an adult the idea of programming the playstation was very appealing. The first sprite I made was done without any concept of loop and arrays. I spent a lot of time figuring out how the cube and ball demo worked piece by piece I was learning. Eventually I bought a PC and this is when I really started programming now I cant really see any way I could ever live without one

About import by hash to my understanding this is how shell code does import by hash -

1] get base address of kernel32 (a few ways exist best one of all requires only 16 bytes but doesnt work with win9x)
2] use own version of GetProcessAddress to locate process by looking up the export RVA tables
3] also convert RVA to VA so that your code can call the process
4] find LoadLibaryA using above GetProcessAddress
5] Load new libraries using LoadLibraryA - find process using own version of GetProcessAddress

now how does the hash fit into all this why does the hash not change from ME,XP,Vista and also across service packs. Import by ordinals I dont understand at all but I know enough to know that it is unreliable (info gained from in4k) why is import by hash not as unreliable as import by ordinals. How does the hash relate to the address? these hashes are far too large to be offsets within the DLL so I assume that the hash is matched against one of the feilds within the export RVA table does that mean that the hash is sort of like a finger print for the process? is it possible for a hash from Kernel32 to be identical to a hash from opengl32 if so how then do you avoid looking up the wrong library

Edit - Also do you think that this is acceptable behaviour?
That prod uses an external program to find the process address for each process called. The funny thing is the coder is doing some hard core coding to manually compress the PE header but if he went just a little more hardcore he could have included the code to load the libraries manually and this code would easily have fitted into the padding (82 bytes of padding) that he left in the header

Sorry if this is too low level for you guys

« on: July 04, 2008 »
At last it is finished. This is an advertro promoting this fine forum. Its a 256 byte intro that features vertical scrolling text, good colour pallet, great generated music, and an escape on any key down (as well as some other more technical and boring features that arent visible to the end user)

To run this intro it is prefered that you have MS-DOS installed with a SoundBlaster card and a VGA Adapter. Failing that you can still run this on Windows XP so long as a VGA adapter or VGA compatible gfx card is present. Failing that you can run this in an emulator best one is DosBox get it here

 org_100h -
 pouet -
 intro-inferno -

Edit - added intro-inferno URL

General chat / Happy Independence Day
« on: July 04, 2008 »
Wishing all our USA members a happy 4th of July. Have fun people and dont go getting into trouble

Useful links / Small Win32 artical
« on: July 02, 2008 »
A useful artical on creating smaller executeables, the author focuses on Visual Studios 6. but much of the content is good reading. Does anyone have similar links that are targeting VS express 2008?

GFX & sound / org_100h banner needed
« on: July 01, 2008 »
Anyone here that is good at photoshop? I need a banner for my site -

I give the artist free reign over it so long as it looks nice with the rest of the site. The banner should read 'org_100h' (in lower case but big font size) and 'size matters' (lower case in half font size used for site name) the file type should be PNG and the banner should fit into the space at the top of the web page. Any thing goes with the back ground and placement of the site name + slogan.

wanna help me with this?

General chat / MOVED: Old Amiga Stuff
« on: June 26, 2008 »
This topic has been moved to USEFUL LINKS.
nice links man I think it is better placed in useful links

Projects / textmode please test on vista
« on: June 19, 2008 »
This is a tiny test to see if Vista at least attempts to emulate Dos Text Mode. As I dont have Vista myself I need someone who does to test for me.

The output should read 'HELLO WORLD' in multi colour with a square cursor blinking at position 5 down and 16 accross

If this does run please use escape key to exit and see if it does close for you

General chat / Moving to a new gaff
« on: June 16, 2008 »
I am moving to a new house tomarrow so I am gonna be around a little less often over the next week. Just until I get settled in. The new place is great much cheaper (only 35 euros per week) and my room is bigger. Its gonna be me and three of my best friends all under one roof. Its gonna be a good laugh. One of my friends has a wireless connection so I will still be popping in. I just cant be hogging his laptop on him.

Challenges & Competitions / [PLANTLIFE] REGROWTH
« on: June 14, 2008 »
Hey guese Im first to put together an entry, well here it is. This is done in ps2Yabasic you will need an emulator in order to run it get the emulator here.

Open the file "[PLANTLIFE]REGROWTH.txt" in the emulator
Then select run program > run
Press escape to exit at any time

Edit - Updated sky motion based on Xalthorns sin scroll suggestion and speeded up the code a little too while I was at it. Im much more happy with this now. Thanks for the motivation Xalthorn

Yabasic / Yabasic 3
« on: June 10, 2008 »
I just discovered that there are plans underway to release yabasic version 3.0

I have already asked that on that forum for support of the ps2yabasic version. I will be keeping a close eye on this one

Useful links / This has to be seen to be believed
« on: June 03, 2008 »

Wow :o

pascal source code released and it has been ported to Unix and get this Gameboy Advanced

How can that be possible on a mere 4Mhz machine that lacks even a pipeline let alone a proper graphics card. I dont think it was released during the reign of the 8088 but if it were then man thats some advanced stuff to be doing at that time in the demoscene (or was it cracktro scene back then)

Pages: 1 [2] 3 4 5