Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Random Directions Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
pluckster




PostPosted: Wed Jan 12, 2005 6:12 pm   Post subject: Random Directions Problem

yes after i got the pics and directions to work, the program wouldnt make the ants go up and down just side to side


code:
% Animal AI Food

View.Set ("title:Ant Farm: Real Life")
setscreen ("graphics:1000;650")
setscreen ("offscreenonly")

%The Ant Record
type ants :
    record
        y : int
        x : int
        movey : int
        movex : int
        movecount : int
        memory : boolean
        energy : int
    end record

var pic : array 1 .. 9 of int
var ant : array 1 .. 8 of ants
var foody : int
var foodx : int
var q, p, o, z : int

%Direction proc
procedure Direction
    for s : 1 .. 8

        randint (q, 1, 50)


        randint (p, 0, 50)

        o := (p + q)

        case o of
            label 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 :
                ant (s).movex := 1
            label 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50 :
                ant (s).movey := 1
            label 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75 :
                ant (s).movex := -1
            label 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100 :
                ant (s).movey := -1
        end case
    end for
end Direction

%MoveCount proc
procedure MoveCount

    for f : 1 .. 8
        randint (z, 1, 200)
        ant (f).movecount := z
    end for

end MoveCount

%MovingUp proc
procedure MovingUp

    for i : 1 .. 8
        if ant (i).movecount <= 0 then
            MoveCount
        elsif ant (i).movex = -1 then
            ant (i).x += -1
            Pic.Draw (pic (4), ant (i).x, ant (i).y, picMerge)
        elsif ant (i).movex = 1 then
            ant (i).x += 1
            Pic.Draw (pic (5), ant (i).x, ant (i).y, picMerge)
        elsif ant (i).movey = -1 then
            ant (i).y += -1
            Pic.Draw (pic (2), ant (i).x, ant (i).y, picMerge)
        elsif ant (i).movey = 1 then
            ant (i).y += 1
            Pic.Draw (pic (3), ant (i).x, ant (i).y, picMerge)
        end if
    end for


end MovingUp

%WallCollide proc
/*
procedure WallCollide
    for g : 1 .. 8

        if ant (g).y >= 0 or ant (g).y <= maxy then
            ant (g).movey := -ant (g).movey
        elsif ant (g).x >= 0 or ant (g).x <= maxx then
            ant (g).movex := -ant (g).movex
        end if

    end for
end WallCollide
*/
%Random food locations
randint (foody, 50, (maxy - 50))
randint (foodx, 50, (maxx - 50))

%Random ant locations
for i : 1 .. 8

    randint (ant (i).y, 50, (maxy - 50))
    randint (ant (i).x, 50, (maxx - 50))
    ant (i).movey := 0
    ant (i).movex := 0
    ant (i).energy := 100
end for

% Drawing of the food box
pic (1) := Pic.FileNew ("food.bmp")
Pic.Draw (pic (1), foodx, foody, picMerge)

%Readying Ant Pics
pic (2) := Pic.FileNew ("ant_up.bmp")
pic (3) := Pic.FileNew ("ant_down.bmp")
pic (4) := Pic.FileNew ("ant_left.bmp")
pic (5) := Pic.FileNew ("ant_right.bmp")


%Ant Moving Variable declared
for w : 1 .. 8

    Direction

    MoveCount

    if ant (w).movey = -1 then
        Pic.Draw (pic (3), ant (w).x, ant (w).y, picMerge)
    elsif ant (w).movey = 1 then
        Pic.Draw (pic (2), ant (w).x, ant (w).y, picMerge)
    elsif ant (w).movex = -1 then
        Pic.Draw (pic (4), ant (w).x, ant (w).y, picMerge)
    elsif ant (w).movex = 1 then
        Pic.Draw (pic (5), ant (w).x, ant (w).y, picMerge)
    end if

end for



%Main Program

loop

    Pic.Draw (pic (1), foodx, foody, picCopy)
    MovingUp
    View.Update
    cls

end loop


please post suggestions
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 1 Posts ]
Jump to:   


Style:  
Search: