Computer Science Canada

help with an intro screen

Author:  babesjersey4 [ Sat Jun 04, 2005 10:12 am ]
Post subject:  help with an intro screen

I am creating a game that runs the intro screen has an Input.Pause and then starts the game, the only problem is the background of the intro screen does not clear completely, I have used cls and have reset the background, yet it still does not work, is their anything else I can do?

Author:  syphon4 [ Sat Jun 04, 2005 11:13 am ]
Post subject:  screen

try drawing a plain white screen over top of the starting one......

code:
drawfillbox (0, 0, maxx, maxy, 0)

Author:  lyam_kaskade [ Sat Jun 04, 2005 9:28 pm ]
Post subject: 

If you've used cls, there might be a problem with your code. I recommend posting it.

Author:  babesjersey4 [ Sat Jun 04, 2005 10:15 pm ]
Post subject: 

code:

View.Set ("noecho,nocursor")
setscreen ("graphics")

% Set constants = ord value of the arrow keys
const RIGHT := 205
const LEFT := 203
const SHOOT := 32
const MAXMENGROUND := 3

var menground := 0     %counts how many men are on the ground
var score := 0 % keeps track of score
var groundCount := 0 %how many parachutters are on the ground
var gunnerHit := false %gunner has not been hit
var gameOver := false %player is still alive

%shot is off the screen to avoid collision with parachute dude
var bulletX, bulletY := -100
var shooting := false %the ship is not firing

%default ship position
var gunnerX := maxx div 2
var gunnerY := 15

var parachuters := 0 % how many parachutes are dropping


Draw.FillBox (0, 0, maxx, maxy, black)
colour (black)
Text.ColorBack (white)
cls

%When a parachuter is hit, have him bleed
procedure paraHit (x, y : int)

    var blood : int := Pic.FileNew ("blood.jpg")     %load the picture

    Pic.Draw (blood, x, y, picCopy)       % draw blood

    delay (1000)

    drawfillbox (x, y, x + 45, y + 50, white) %erase the blood

end paraHit


process introscreen

        const Y := 100 %number for delay
        const X := 1000 %number for delay
       
        Draw.FillBox (0, 0, maxx, maxy, black)
        colour (white)
        Text.ColorBack (black)

        delay (Y)
        locate (5, 35)
        put "W" ..
        delay (Y)
        put "E" ..
        delay (Y)
        put "L" ..
        delay (Y)
        put "C" ..
        delay (Y)
        put "O" ..
        delay (Y)
        put "M" ..
        delay (Y)
        put "E" ..
        locate (7, 25)
        locate (8, 33)
        put "The situation: "
        locate (9, 22)
        put "Enemy parachuters are dropping from the sky."
        delay (X)

        locate (11, 33)
        put "Your mission: "
        locate (12, 22)
        put "Shoot as many parachuters as possible. If they"
        locate (13, 22)
        put "get as many as three men on the ground, it's"
        locate (14, 22)
        put "Game Over for us."

        delay (X)
        locate (16, 22)
        put "Good luck, and may we triumph for all things"
        locate (17, 22)
        put "good!"
        locate (19, 30)
        put "Press the space bar to continue."
        cls

       
end introscreen

process men

    var para : int := Pic.FileNew ("men.jpg")      %load the picture
    % controls a single parachuter which flies down from top of screen
    var menXSpeed := 0
    var menYSpeed := Rand.Int (1, 3)
    var men_Y : int := 0 %stores position of men on Y axis
    parachuters += 1    %increase the number of parachuters
    var menX := Rand.Int (15, 585)


    for decreasing menY : 385 .. 15 by menYSpeed

        Pic.Draw (para, menX, menY, picCopy) %draw the parachuter
        delay (20)
        drawfillbox (menX, menY, menX + 50, menY + 50, black)
        men_Y := menY
        exit when gameOver

        % check if parachuters is on the ground
        if men_Y <= 50 then
            menground += 1
            exit
        end if

        % check if parachuters has been hit by a shot
        if abs (menX - bulletX) < 30 and abs (menY - bulletY) < 30 then
            paraHit (menX, menY)
            score += 100 % adds 100 to score when bullet hits man
            shooting := false
            exit when gameOver
            exit

        end if
    end for
    parachuters -= 1

end men


process clouds
    var cloud : int := Pic.FileNew ("cloud.jpg") % load picture
    var cloudY := 300

    for cloudX : 15 .. 625
        Pic.Draw (cloud, cloudX, cloudY, picCopy)
        Draw.FillBox (cloudX, cloudY, cloudX + 70, cloudY + 70, white)
    end for

end clouds

process moremen         %makes 1-5 men come down randomly

    loop
        if parachuters <= 2 then
            fork men
            % don't let more than 3 on at a time
        else
            delay (100)
        end if
        delay (100)
        exit when gameOver
    end loop

end moremen

%The ship fires
process fire (xc : int)

    shooting := true     % a shot is being fired

    var shot : int := Pic.FileNew ("shot.jpg")     %load the picture

    bulletX := xc     %set the position of the bullet to be aligned with gunner

    % fire the bullet
    for y : gunnerY + 55 .. 385 by 5     %start shot from gunner's position to the top of the screen
        exit when gameOver
        exit when not shooting

        bulletY := y
        Pic.Draw (shot, bulletX, bulletY, picCopy)            % draw the shot
        delay (5)
        Draw.FillBox (bulletX, bulletY, bulletX + 5, bulletY + 22, black)     %erase the shot
    end for

    % move the bullet off the screen so no men can "bump into it"
    bulletX := -100
    bulletY := -100

    shooting := false

end fire

process showScore
    Draw.FillBox (0, 0, maxx, maxy, white)
    % displays score and remaining lives at top of screen
    loop
        % wipe out old score and display current score
        Draw.FillBox (0, maxy - 100, maxx, maxy, white)
        put "Score : ", score
        locate (1, 5)
        put "Men on ground : ", menground
        locate (2, 5)
        % Control when the game is actually over
        if menground = 3 then
            gameOver := true
        end if

        delay (250)

    end loop

end showScore

%draws and moves the gunner
process gunner
    var keyPress : string (1)

    var gunner : int := Pic.FileNew ("gunner.jpg")     %load the picture

    Pic.Draw (gunner, gunnerX, gunnerY, picCopy)     %draw the picture to the screen

    % flush any characters typed but not read yet
    % this keeps ship from jumping away from starting
    % point immediately when it appears
    loop
        exit when not hasch
        getch (keyPress)     % Discard this character
    end loop


    loop
        getch (keyPress)

        % erase the ship at current location before moving
        Draw.FillBox (gunnerX, gunnerY, gunnerX + 50, gunnerY + 50, black)

        % If user pressed an arrow key, move gunner
        if ord (keyPress) = RIGHT and gunnerX < maxx - 15 then
            gunnerX += 25
        elsif ord (keyPress) = LEFT and gunnerX > 15 then
            gunnerX -= 25
        elsif ord (keyPress) = SHOOT and shooting = false then
            fork fire (gunnerX + 19)
            exit when gameOver
        end if
        exit when gameOver
        Pic.Draw (gunner, gunnerX, gunnerY, picCopy)     %draw the ship
    end loop
end gunner



%main program
% fork clouds

fork introscreen
Input.Pause

cls
View.Update

 colorback (black)
Draw.FillBox (0, 0, maxx, maxy, black)
colour (white)
score := 0
menground := 0

fork showScore
fork moremen
fork gunner

if groundCount = MAXMENGROUND then
    cls
    gameOver := true
    put "Game Over"
end if



the intro is cheesy but i just want it to work before i brush it up

Author:  MysticVegeta [ Sun Jun 05, 2005 7:00 am ]
Post subject: 

OMG! worst use of processes i have seen, except there were these 2 times but nevermind. The processes are screwing up your cls problem, Why dont you use procedures and try looping them?

Author:  babesjersey4 [ Sun Jun 05, 2005 9:02 am ]
Post subject: 

ok, i'll do that, thanks so much for the advice

Author:  MysticVegeta [ Sun Jun 05, 2005 10:09 am ]
Post subject: 

Try to minimize your process use just for bg music. But now you dont even need process for that, because the built-in function of turing 4.0.5
code:
Music.PlayFileLoop

So use of processes is now really "0"

Author:  Cervantes [ Sun Jun 05, 2005 10:20 am ]
Post subject: 

MysticVegeta wrote:

So use of processes is now really "0"

Much as I hate the way processes are usually used, I have to disagree with you there. Mckenzie mentioned somewhere sometime ago, processes are just misused. For things such as, in a game of chess, computer AI while waiting for the user's input, processes can be a good thing.
But note: the two processes occuring in this type of program do not affect one another. The computer is searching for the best possible move, but that does not affect the code that waits for user input. Likewise, the code that waits for user input does not affect the search for the best possible move(s). Also, this kind of thing cannot really be done without processes. Say your AI uses a particular procedure and lots of recursion. You could not stick that in the same loop as the input loop because the recursion would take quite some time, so the input would not actually be allowed for most of the time. (Plus, you don't want to loop your AI checking!)
So, for something like AI for chess, processes may be a good thing. But yes, almost every process used in the Turing section here is misused.

Author:  MysticVegeta [ Sun Jun 05, 2005 1:36 pm ]
Post subject: 

Just a question Cervantes, how much knowledge and practise and work does it take to program a successful chess game with normal level of AI?

Author:  Cervantes [ Sun Jun 05, 2005 3:35 pm ]
Post subject: 

Well, I've never done it myself, but I would say the hardest part would be the AI, for which you'd probably need a strong background in recursion.
Plus, you have to be good at chess. Smile

Author:  c0bra54 [ Sun Jun 05, 2005 3:55 pm ]
Post subject: 

yeh.. AI = ew.. however tic tac toe AI = easy.. and checkers i'msure wouldn't be TO hard.... ust chess, you can't program for possible outcomes.. you need to program.. like.. thinking Razz

Author:  [Gandalf] [ Sun Jun 05, 2005 4:29 pm ]
Post subject: 

For chess you use game tree's. You don't program all the possible outcomes, but the program has to calculate the moves. Since there are LOTS of possible moves in chess, to get a good depth search you don't look at all the possibilities, just the likely ones. There are many strategies of making more complex ai's, and Turing is not the best language for it.

Yeah... so, it would be nice to have a chess program from Turing. It would probably be slow and all, but it would still be great to have some kind of ai. Somebody did a start once. I remember you could do all the moves and everything, but there was no ai or checkmate/special moves/rules.

Author:  MysticVegeta [ Sun Jun 05, 2005 6:42 pm ]
Post subject: 

well i think one of the points that Cervantes mentioned was pretty good - you have to be good at chess. Thats a good point, i think when Gandalf said "special moves", we need to figure out the special moves first in order to program them, and then check for conditions like - the computer doesnt get beaten up first, the computer still will have place to move, the computer has place to move, etc. Congratz we have programmed 1/100th piece of AI required for normal level chess Blowing up Blowing up

Author:  [Gandalf] [ Sun Jun 05, 2005 7:08 pm ]
Post subject: 

Yeah, you have to be decent in chess, true. What I meant with "special moves" was like en passant and castle...

For a lot of opening moves and endgame moves there are things called "opening books" and "endgame databases" that just have a bunch of different scenarios for around 4-12 moves so that the beginnings go fast and according to predefined strategies.

In the middle, main game where the computer is calculating, it doesn't have to find a "good move". What it usually does is put a value on the different positionings and pieces then try and find a combination of moves which gain it that advantage.

I spent a lot of time on chess programming, that's what really introduced my to programming, and I was doing this stuff even before I knew how to program.

Author:  c0bra54 [ Sun Jun 05, 2005 7:46 pm ]
Post subject: 

aaa lol.. i think compsci should like.. try it.. everyone here , like have people, make 3D models, and just render as pictures... and have boards, and everything, and have like a 3 person team on how to make AI research it an everything.. i think this could be pretty crazy...


also about pocess's during the opponent (player's) move.. wouldn't that not work right, since the compter wouldn't be taking into account, the move that the player is making.. since if it decided on it's move, before the player moved, then the computer moved.. wouldn't it never take the last move into event.. so wouldn't it be like.. really REALLY easy computer.. since if you put it into check, it doens't know that Razz so it'll just lose...???

Author:  [Gandalf] [ Sun Jun 05, 2005 9:19 pm ]
Post subject: 

You don't really need 3d models for a good chess program Confused

Quote:
also about pocess's during the opponent (player's) move.. wouldn't that not work right, since the compter wouldn't be taking into account, the move that the player is making.. since if it decided on it's move, before the player moved, then the computer moved.. wouldn't it never take the last move into event.. so wouldn't it be like.. really REALLY easy computer.. since if you put it into check, it doens't know that Razz so it'll just lose...???

No, the computer would be thinking both during the players move and its own move. Think about it; thinking while the person makes their move is still advantageous, although not as much as during the move. If the ai thinks of a bunch of possibilities while the human is moving then those possibilities are narrowed down when the move is made - so now the computer can focus on those 'branches'. The computer thinks more than one move ahead, just like a good chess player would. It can predict that you will check/checkmate it so it would avoid that outcome.

Author:  c0bra54 [ Sun Jun 05, 2005 9:40 pm ]
Post subject: 

ooo ok.. also i was thiking (while working on other programming hwk :S

what about if to do it, you did kinda program for every outcome.. but not really.. like if you said

for every piece where can it move, for every spot it can move how many pieces of mine, can get taken, how many pieces can i take.. and those are also not only how many but what.. also it has immediate moves, like

if he can take King then Queen, move not ok... and it has it be a certain value ... positive you tkae, negative you don't take, and then it taqkes numbers and branches that do make the grade.

then it assumes it did that move, then it says where can the human move... takes those values, and then makes it's final decision, based on not only the highest value, but then also what piece s taking what.. like it's kinda dumb for him to move his bishop if then the player can take his, but a rook (castle) to bishop would be ok, and a knight to bishop perhaps better.. like then instead of checking every branch, it see it's best move, then it finds the worst move the human has comparitivly.. and then decides...

ny input (and i dun just wanna goto google and type, how to make chess AI)


thx - might seriously consider this

and usin a function would be an excellent way to return the value

Author:  [Gandalf] [ Mon Jun 06, 2005 4:18 pm ]
Post subject: 

Well, ya. Most heavy duty chess engines (programs) do some heavy duty calculations. Those calculations being checking the advantages and disadvantages of every move possible. Which is how we get search depth. If the computer is looking ahead towards its next move, then players move, then its move again, that's a search depth of 2. The higher the search depth the better the program will be able to make its decision. What has to be kept in mind is the time that will be spent making the move. The larger the search depth the more possibilities, exponentially, so the longer it will take to make the neccessary calculations. The thing is, to decrease this time you should take into consideration some things which are excluded as soon as they are noticed by the program, obvious "don't go there" situations.

The computer doesn't only take the values of the peaces into consideration, it takes positioning, checkmate oppurtunities, control of the center of the board, attack/defend, king safety, and a large number of other variables. The best program has a good balance of each of these.

Finally, just as a note of interest. Computers don't "think" like humans do. Humans look at the board, then they immediately dismiss the bad positions, and focus on places where they can develop. Computers on the other hand, are much better at doing brute force calculations, and so they use this method more. It's still surprising that even the best supercomputer chess boxes in the world are about even to the best humans in the world.

Author:  c0bra54 [ Mon Jun 06, 2005 5:12 pm ]
Post subject: 

yeh.. i am still thinking of maybe working on it during the summer, becuase onceyou develop a good system of what the AI will look for, and hwo to tell it what and where everything is, it probly wouldn't be impossible to set one up, and let it take lik 3 or 4 mins / move to a depth of 2 moves... be interresting to see if it would a descent opponent (prolly not.. but still)

Author:  [Gandalf] [ Mon Jun 06, 2005 5:39 pm ]
Post subject: 

Well, that matters... on how well it is coded and optimized. Seeing as how Turing marmolously (yep Smile) increases requirements for doing things, 2-3 minutes could probably do a depth of 2 or maybe 3, ya. The thing is, well I don't know, but a fairly decent played could crush a program with a depth of 2. Still, if you get it up to 3 maybe it'll be a pretty good challenge.

The two best commercial programs in the world go to search depths of 8-12, even 14 sometimes (longer games).

Author:  c0bra54 [ Mon Jun 06, 2005 9:51 pm ]
Post subject: 

yeh.. but this is mainly just for testing, to see what it would be like..


: