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

Username:   Password: 
 RegisterRegister   
 found my old mine sweeper game!!! give it a play!!
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TokenHerbz




PostPosted: Wed Dec 13, 2017 12:43 am   Post subject: found my old mine sweeper game!!! give it a play!!

Turing:

var ROWS : int := 20
var COLUMNS : int := 20
const s := 20
var MINE_PERCENT : real := .20
var MINES : int := round (MINE_PERCENT * (ROWS * COLUMNS))
var GAME_OVER : boolean := false
var WINNER : boolean := false
const GB := 2

var Options := Window.Open ("Graphics: 300;200, position: center;center, title: Game Options:, nocursor,noecho,nobuttonbar")
var option : int := 0
var ox, oy, ob : int
loop
    colorback (95)
    cls
    Mouse.Where (ox, oy, ob)
    put "Please Select one of the Following:"
    put ""
    put "  EASY    (10 x 10 grid @ 08% mines)"
    put "  MEDIUM  (15 x 15 grid @ 12% mines)"
    put "  HARD    (20 x 20 grid @ 16% mines)"
    put "  BRUTAL  (25 x 25 grid @ 20% mines)"
    put "  CUSTOM: (?? x ?? grid @ ??% mines)"
    put ""
    put "Will Auto fix your custom to work!"
    put ""
    put "Your Choice is... " ..

    if oy >= 150 and oy <= 170 then
        for i : 1 .. 3
            Draw.Box (5 + i, 150 + i, 295 - i, 170 - i, 7)
        end for
        put "(EASY)"
        if ob = 1 then
            option := 1
            ROWS := 10
            COLUMNS := 10
            MINES := round (.08 * (ROWS * COLUMNS))
        end if
    elsif oy >= 135 and oy < 150 then
        for i : 1 .. 3
            Draw.Box (5 + i, 135 + i, 295 - i, 155 - i, 7)
        end for
        put "(MEDIUM)"
        if ob = 1 then
            option := 2
            ROWS := 15
            COLUMNS := 15
            MINE_PERCENT := .08
        end if
    elsif oy >= 120 and oy < 135 then
        for i : 1 .. 3
            Draw.Box (5 + i, 120 + i, 295 - i, 140 - i, 7)
        end for
        put "(HARD)"
        if ob = 1 then
            option := 3
            ROWS := 20
            COLUMNS := 20
            MINE_PERCENT := .12
        end if
    elsif oy >= 100 and oy < 120 then
        for i : 1 .. 3
            Draw.Box (5 + i, 100 + i, 295 - i, 120 - i, 7)
        end for
        put "(BRUTAL)"
        if ob = 1 then
            option := 4
            ROWS := 25
            COLUMNS := 25
            MINE_PERCENT := .16
        end if
    elsif oy >= 85 and oy < 100 then
        for i : 1 .. 3
            Draw.Box (5 + i, 85 + i, 295 - i, 105 - i, 7)
        end for
        put "(CUSTOM)"
        if ob = 1 then
            option := 5
            loop
                cls
                Mouse.Where (ox, oy, ob)
                put "You have chosen CUSTOM settings:"
                put "Select ENTER when you are ready!"
                put ""
                put "    -    ROWS:        ", ROWS, "     +"
                put "    -    COLUMNS:     ", COLUMNS, "     +"
                put ""
                put "    -    Mine Percent: ", (MINE_PERCENT * 100), "%   +"
                put ""
                put "    Mines: (", MINES, ") on a (", ROWS * COLUMNS, ") grid!"
                put ""
                put "          ( E N T E R )"
                if oy >= 135 and oy <= 150 then
                    if ox <= 50 and ox >= 25 then
                        for i : 1 .. 3
                            Draw.Box (25 + i, 135 + i, 50 - i, 150 - i, 7)
                        end for
                        if ob = 1 then
                            ROWS -= 1
                        end if
                    elsif ox <= 250 and ox >= 225 then
                        for i : 1 .. 3
                            Draw.Box (225 + i, 135 + i, 250 - i, 150 - i, 7)
                        end for
                        if ob = 1 then
                            ROWS += 1
                        end if
                        %%% ADD KEYBOARD INPUTS INTO THIS LATER!!!!
                        %  elsif ox <= 200 and ox >= 60 then
                        % for i : 1 .. 3
                        %      Draw.Box (60 + i, 135 + i, 200 - i, 150 - i, 7)
                        %  end for
                        %  if ob = 1 then
                        %     loop
                        %%Should add some input for actual keyboard inputs.
                        %       exit
                        %   end loop
                        %  end if
                    end if
                    if ROWS <= 5 then
                        ROWS := 5
                    end if
                elsif oy >= 120 and oy < 135 then
                    if ox <= 50 and ox >= 25 then
                        for i : 1 .. 3
                            Draw.Box (25 + i, 120 + i, 50 - i, 135 - i, 7)
                        end for
                        if ob = 1 then
                            COLUMNS -= 1
                        end if
                    elsif ox <= 250 and ox >= 225 then
                        for i : 1 .. 3
                            Draw.Box (225 + i, 120 + i, 250 - i, 135 - i, 7)
                        end for
                        if ob = 1 then
                            COLUMNS += 1
                        end if
                    end if
                    if COLUMNS <= 5 then
                        COLUMNS := 5
                    end if
                elsif oy >= 88 and oy < 103 then
                    if ox <= 50 and ox >= 25 then
                        for i : 1 .. 3
                            Draw.Box (25 + i, 88 + i, 50 - i, 103 - i, 7)
                        end for
                        if ob = 1 then
                            MINE_PERCENT -= .01
                        end if
                    elsif ox <= 250 and ox >= 225 then
                        for i : 1 .. 3
                            Draw.Box (225 + i, 88 + i, 250 - i, 103 - i, 7)
                        end for
                        if ob = 1 then
                            MINE_PERCENT += .01
                        end if
                    end if
                    if MINE_PERCENT <= .01 then
                        MINE_PERCENT := .01
                    elsif MINE_PERCENT >= .99 then
                        MINE_PERCENT := .99
                    end if
                end if
                MINES := round (MINE_PERCENT * (ROWS * COLUMNS))
                if oy <= 50 and oy > 10 then
                    if ox <= 200 and ox >= 70 then
                        for i : 1 .. 3
                            Draw.Box (70 + i, 10 + i, 200 - i, 50 - i, 7)
                        end for
                    end if
                    if ob = 1 then
                        exit
                    end if
                end if
                View.Update
                delay (100)
            end loop
        end if
    end if
    exit when option not= 0
    View.Update
    delay (100)
end loop
cls

Window.Close (Options)

View.Set ("Graphics:" + intstr ((ROWS * s) + 50) + ";" + intstr ((COLUMNS * s) + 100) + ", position: center;center, title: Derek's MineSweeper V1.0 Alpha, nobuttonbar, offscreenonly, noecho")
var valueFont : int := Font.New ("serif:12")
class Tiles
    import GAME_OVER, s, valueFont
    export inits, draw, setMine, show_mine_test, check_tile, is_a_mine, setValue, reveal_zeros, uncover, value, is_uncovered, is_flagged

    var x, y : int
    var is_a_mine : boolean := false
    var is_flagged : boolean := false
    var is_uncovered : boolean := false
    var value : string := ""
    var display : string := ""
    var colr : int := 95
    var show_value : boolean := false

    proc inits (x_, y_ : int)
        x := x_ * s
        y := y_ * s
    end inits

    fcn setMine : boolean
        if is_a_mine = false then
            is_a_mine := true
            value := "*"
            result true
        end if
        result false
    end setMine

    proc check_tile (mx_, my_, mb_ : int)
        if mx_ >= x and mx_ <= x + s and my_ >= y and my_ <= y + s then
            if mb_ = 100 then
                if is_uncovered = false then
                    if is_flagged = false then
                        is_flagged := true
                        colr := 3
                        display := "?"
                    else
                        is_flagged := false
                        colr := 95
                        display := ""
                    end if
                end if
            else
                if is_flagged = false then
                    if is_uncovered = false then
                        if is_a_mine = true then
                            GAME_OVER := true
                            colr := 7
                        else
                            colr := 0
                            show_value := true
                            display := value
                            is_uncovered := true
                        end if
                    end if
                end if
            end if
        end if
    end check_tile

    fcn reveal_zeros : boolean
        if is_uncovered = true then
            if value = "0" then
                result true
            end if
        end if
        result false
    end reveal_zeros

    proc uncover
        colr := 0
        show_value := true
        display := value
        is_uncovered := true
    end uncover

    proc setValue (value_ : int)
        value := intstr (value_)
    end setValue

    proc draw
        Draw.Box (x, y, x + s, y + s, 7)
        Draw.FillBox (x + 1, y + 1, x - 1 + s, y - 1 + s, colr)
        Font.Draw (display, x + (s div 4), y + (s div 4), valueFont, 7)
    end draw

    proc show_mine_test
        if is_a_mine = true then
            Font.Draw (value, x + (s div 4), y + (s div 4), valueFont, 7)
        end if
    end show_mine_test

end Tiles

var grid : array 1 .. ROWS + GB, 1 .. COLUMNS + GB of ^Tiles
for r : 1 .. ROWS
    for c : 1 .. COLUMNS
        new Tiles, grid (r, c)
        grid (r, c) -> inits (r, c)
        grid (r, c) -> draw
    end for
end for
var tempr, tempc : int := 0
for m : 1 .. MINES
    loop
        tempr := Rand.Int (2, ROWS - 1)
        tempc := Rand.Int (2, COLUMNS - 1)
        exit when grid (tempr, tempc) -> setMine = true
    end loop
end for

var test : int := 0
for r : 2 .. ROWS - 1
    for c : 2 .. COLUMNS - 1
        if grid (r, c) -> is_a_mine = true then
            test += 1
        end if
    end for
end for

proc SOLVE
    var amount : int := 0
    var row, col : int
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_a_mine = false then
                for cr : r - 1 .. r + 1
                    for cc : c - 1 .. c + 1
                        if grid (cr, cc) -> is_a_mine = true then
                            amount += 1
                        end if
                    end for
                end for
                grid (r, c) -> setValue (amount)
                amount := 0
            end if
        end for
    end for
end SOLVE
SOLVE

proc draw_top_info
    var flagged_amount : int := 0
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_flagged = true then
                flagged_amount += 1
            end if
        end for
    end for
    Font.Draw ("MINES:" + intstr (MINES - flagged_amount), maxx div 3, maxy - 10, valueFont, 7)
end draw_top_info

proc CHECK_WIN
    var checker : int := 1
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_uncovered = true then
                checker += 1
            end if
        end for
    end for
    if checker + MINES = ROWS * COLUMNS then
        WINNER := true
    end if
    checker := 0
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_a_mine = true then
                if grid (r, c) -> is_flagged = true then
                    checker += 1
                end if
            end if
        end for
    end for
    if checker = MINES then
        WINNER := true
    end if
    var cccc : int := 0
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            if grid (r, c) -> is_a_mine = false then
                if grid (r, c) -> is_uncovered then
                    cccc += 1
                end if
            end if
        end for
    end for
    if cccc = ((ROWS + 1) * (COLUMNS - 1) - MINES) then
        WINNER := true
    end if
end CHECK_WIN

Mouse.ButtonChoose ("multibutton")
var mx, my, mb, ml, mm, mr : int

loop
    cls
    Mouse.Where (mx, my, mb)
    ml := mb mod 10     %0/1
    mm := (mb - ml) mod 100     %0/10
    mr := mb - mm - ml     %0/100

    if mb = 1 or mb = 10 or mb = 100 then
        for r : 2 .. ROWS - 1
            for c : 2 .. COLUMNS - 1
                grid (r, c) -> check_tile (mx, my, mb)
                if grid (r, c) -> reveal_zeros = true then
                    for rr : 2 .. ROWS - 1
                        for cc : 2 .. COLUMNS - 1
                            if grid (rr, cc) -> value = "0" then
                                for rrr : (rr - 1) .. (rr + 1)
                                    for ccc : (cc - 1) .. (cc + 1)
                                        grid (rrr, ccc) -> uncover
                                    end for
                                end for
                            end if
                        end for
                    end for
                end if
            end for
        end for
    end if

    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            grid (r, c) -> draw
            %    grid (r, c) -> show_mine_test
        end for
    end for
    draw_top_info
    View.Update
    delay (50)
    exit when GAME_OVER = true
    exit when WINNER = true
end loop
if GAME_OVER = true then
    for r : 2 .. ROWS - 1
        for c : 2 .. COLUMNS - 1
            grid (r, c) -> show_mine_test
        end for
    end for
    View.Update
    Input.Pause
end if
if WINNER = true then
    put "WINNNNNNNNER"
    View.Update
    Input.Pause
end if
Sponsor
Sponsor
Sponsor
sponsor
TokenHerbz




PostPosted: Wed Dec 13, 2017 12:58 am   Post subject: RE:found my old mine sweeper game!!! give it a play!!

Also found my old old tic tac toe, its got some GARBAGE AI -> someone should make it smart so it never looses!!!! -- at least its kind of commented ##AIDS## must be old

Turing:

%%%%Dereks Tic Tac Toe, Created using a CLASS.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%My Tiles Class is very simple, It lets my create a tile with object properties.  It will have the x,y positions, with the SIZE of X and Y to that location.
%%These tiles will have several data options, displays, font differences, colors, and more things as I add them in.  Its a TILE data, so i can section the screen.
class Tiles
    export init_Tile, draw_Tile, is_Tile_clicked, change_Tile_value, read_Tile_value, is_Tile_playable, change_Tile_colors, change_Tile_playable

    type Position :
        record
            x, y : int
            x1, y1 : int
        end record
    var pos : Position
    type Data :
        record
            font, brdrcolr, fontcolr, bkgrcolr : int
            value : string
            height, width : int
            playable : boolean
        end record
    var data : Data

    %%this init_tile will set all basic values to use the tile.  it will get the x,y max screen pixles to scale
    %%the tiles accordingly, also with this info we will scale the font for the tile to center it correctly and correct sizes.
    proc init_Tile (x, y, x1, y1 : int)
        pos.x := x
        pos.y := y
        pos.x1 := x1
        pos.y1 := y1

        data.value := "NIL"
        data.height := ((pos.y + pos.y1) - pos.y) div 2
        data.font := Font.New ("serif:" + intstr (data.height))
        data.width := Font.Width (data.value, data.font)
        data.brdrcolr := 7
        data.fontcolr := 7
        data.bkgrcolr := 0
        data.playable := true
    end init_Tile

    %%This function checks to see if the mouse (mx,my) locations are within a tiles boundries.
    %%it also has to be playable to return true, otherwise it will return false.
    fcn is_Tile_clicked (mx, my : int) : boolean
        if mx <= pos.x + pos.x1 and mx >= pos.x and
                my <= pos.y + pos.y1 and my >= pos.y then
            result true
        end if
        result false
    end is_Tile_clicked

    %%returns if the tile is playable or not.
    fcn is_Tile_playable : boolean
        result data.playable
    end is_Tile_playable

    %%changes the Tiles Playablility by switching it from true -> false or false -> true
    proc change_Tile_playable
        if data.playable = true then
            data.playable := false
        else
            data.playable := true
        end if
    end change_Tile_playable

    %%this proc is simple it just returns the value of the tile so its easy to get that single peice of info
    %%We will use this to check for wins and things of that sort!!
    fcn read_Tile_value : string
        result data.value
    end read_Tile_value

    %%this lets us change our tile colors
    proc change_Tile_colors (object : string, colr : int)
        if object = "background" then
            data.bkgrcolr := colr
        elsif object = "border" then
            data.brdrcolr := colr
        elsif object = "font" then
            data.fontcolr := colr
        end if
    end change_Tile_colors

    %%Lets us change our tile data, we should re-set the WIDTH of FONT too so everything stays centered!
    proc change_Tile_value (new_value : string)
        data.value := new_value
        data.width := Font.Width (data.value, data.font)
    end change_Tile_value

    %%We can draw the tiles and the data, using NIL its easier to read and we can just avoid drawing it that way.
    %%This set up should be easy to add alot of features later to, like borders, other colors, etc.
    proc draw_Tile
        Draw.FillBox (pos.x, pos.y, pos.x + pos.x1, pos.y + pos.y1, data.bkgrcolr)
        Draw.Box (pos.x, pos.y, pos.x + pos.x1, pos.y + pos.y1, data.brdrcolr)
        if data.value not= "NIL" then
            Font.Draw (data.value, pos.x + ((pos.x1 div 2) - (data.width div 2)), pos.y + ((pos.y1 div 2) - (data.height div 2)), data.font, data.fontcolr)
        end if
    end draw_Tile

end Tiles

%%Players data to use in the game, and also init reset values for them
%Currently set for player to be X and comp(2) to by O and player goes first.
type Players :
    record
        win : boolean
        symbol : string
        turn : boolean
    end record

var player : array 1 .. 2 of Players %%2 = PC
proc init_Players
    for i : 1 .. 2
        player (i).win := false
    end for
    player (1).symbol := "X"
    player (2).symbol := "O"
    player (1).turn := true
    player (2).turn := false
end init_Players
init_Players

%%Don't change these values without reading source.
const GB := 2  %%This is the Grid Buffer Space
var XPIX : int := 300
var YPIX : int := 300
var TOP_BANNER : int := 100   %%DO NOT MAKE TO LITTLE WITHOUT EDITING SOURCE (the Options / INFO in BANNER use this)
var GRID_ROW_AMOUNT : int := 3  %%DO NOT SET LESS THEN 3
var GRID_COLM_AMOUNT : int := 3  %%DO NOT SET LESS THEN 3
%%to make things easier lets declare some values to use simplar
var Xsize : int := XPIX div GRID_ROW_AMOUNT
var Ysize : int := YPIX div GRID_COLM_AMOUNT
var WIN_COUNT : int := 3

%%Options Menu.  This will let us change our grid amount, win_amount, XPIX/YPIX, to start.
%%I eventually want to make these options all clickable and use their own tiles spaced to change stats
%%and we can add more in, like customize colors for strong/borders/etc.
proc OPTIONS_MENU
    var Option_Window := Window.Open ("Graphics:200;200,Title: Options Menu!, Position: center;center, offscreenonly, nubuttonbar, noecho, nocursor")
    loop
        put "This is option Window"
        View.Update
        Input.Pause
        exit
    end loop
    Window.Close (Option_Window)
end OPTIONS_MENU

%%I add 2 pixle on the maxX so that it evens out since the drawing on ZERO has a pixle border where it don't if i draw on the MAXX without it.
var Game_Window := Window.Open ("Graphics:" + intstr (XPIX + 2) + ";" + intstr ((YPIX + TOP_BANNER)) + ",Title: Tic Tac Toe!, Position:center;center, offscreenonly, nobuttonbar, noecho, nocursor")

%%Declareing some needed game values and variables.
var mouseX, mouseY, mouseB : int
%%%%%**********IMPORTANT NOTICE************######
%###########I am going to be buffering my grid 2D array by 2 per side, thats 2/2/2/2 all around the grid
%%This is to make an easy algorithm to check for wins, so we can play this with many many tiles!!!
%%The extra buffer space are N/A and have none important values, we make it to avoid errors doing this!
%% We will keep the normal counter 1 .. Max Row, but start the BUFFERS at 1 - GB and MAX + GB to make this work
var GRID : array (1 - GB) .. (GRID_ROW_AMOUNT + GB), (1 - GB) .. (GRID_COLM_AMOUNT + GB) of ^Tiles
for row : (1 - GB) .. (GRID_ROW_AMOUNT + GB)
    for colm : (1 - GB) .. (GRID_COLM_AMOUNT + GB)
        new Tiles, GRID (row, colm) %%we create buffer tiles and not assign them real values here
        if row > 0 and colm > 0 and row <= GRID_ROW_AMOUNT and colm <= GRID_ROW_AMOUNT then
            GRID (row, colm) -> init_Tile ((row * Xsize) - Xsize, (colm * Ysize) - Ysize, Xsize, Ysize)
        else
            GRID (row, colm) -> init_Tile (0, 0, 0, 0) %%Regester with ZEROS,and will be NIL and wont draw.
            %%Also note we don't have to call the buffer space unless use are useing it, which will
            %%be very limited to only the checking of the symbols.
        end if
    end for
end for
var Win_Counter : int
var Difficulty : string := "easy"  %%easy / medium / hard / impossible
var OPTIONS : ^Tiles  %%%Options and details will be in the BANNER
new Tiles, OPTIONS    %%options set at 1/2 the BANNER Height and
var DETAILS : ^Tiles   %%set on the bottom
new Tiles, DETAILS
%%init these tiles for basic start
OPTIONS -> init_Tile (0, YPIX, XPIX, (TOP_BANNER div 2))
OPTIONS -> change_Tile_value ("OPTIONS")
OPTIONS -> change_Tile_colors ("background", 7)
OPTIONS -> change_Tile_colors ("font", 0)
OPTIONS -> change_Tile_colors ("border", 0)
DETAILS -> init_Tile (0, YPIX + (TOP_BANNER div 2), XPIX, (TOP_BANNER div 2))
DETAILS -> change_Tile_colors ("background", 7)
DETAILS -> change_Tile_colors ("font", 0)
DETAILS -> change_Tile_colors ("border", 0)

%%Rows will be horizontal.  We will check and count each consecutive symbol
%% and return the results.  reach WIN_COUNT is a win.  if we run into a something thats not ours
%% the check end.  We will check both left and right areas first, then go one extra for a total of 2 spaces outwards of checked tile
fcn Check_rows (row_, colm_ : int, symbol_ : string) : int
    Win_Counter := 1
    if GRID (row_ - 1, colm_) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ - 2, colm_) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    if GRID (row_ + 1, colm_) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ + 2, colm_) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    result Win_Counter
end Check_rows
%%Checks the coloms vertically, 5 spaces, (consecetive only)
fcn Check_colms (row_, colm_ : int, symbol_ : string) : int
    Win_Counter := 1
    if GRID (row_, colm_ - 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_, colm_ - 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    if GRID (row_, colm_ + 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_, colm_ + 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    result Win_Counter
end Check_colms
%%Checks the forward slash! / / /
fcn Check_forslash (row_, colm_ : int, symbol_ : string) : int
    Win_Counter := 1
    if GRID (row_ - 1, colm_ - 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ - 2, colm_ - 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    if GRID (row_ + 1, colm_ + 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ + 2, colm_ + 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    result Win_Counter
end Check_forslash
%checks the backslash direction \ \ \
fcn Check_backslash (row_, colm_ : int, symbol_ : string) : int
    Win_Counter := 1
    if GRID (row_ - 1, colm_ + 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ - 2, colm_ + 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    if GRID (row_ + 1, colm_ - 1) -> read_Tile_value = symbol_ then
        Win_Counter += 1
        if GRID (row_ + 2, colm_ - 2) -> read_Tile_value = symbol_ then
            Win_Counter += 1
        end if
    end if
    result Win_Counter
end Check_backslash

%%this will call and use all the checks for possible wins (HORIZONTAL/VERTICAL/CROSS)
% and result depending on the counts for it.  I broke up the checks to make it easier to read/understand.
%%It also checks to make sure there are playable tiles, otherwise the game will stop as STALE MATE (CATS EYE)
fcn Check_for_game_win : boolean
    for row : 1 .. GRID_ROW_AMOUNT
        for colm : 1 .. GRID_COLM_AMOUNT
            for plays : 1 .. 2
                if GRID (row, colm) -> read_Tile_value = player (plays).symbol then
                    if Check_rows (row, colm, player (plays).symbol) >= WIN_COUNT or Check_colms (row, colm, player (plays).symbol) >= WIN_COUNT or
                            Check_forslash (row, colm, player (plays).symbol) >= WIN_COUNT or Check_backslash (row, colm, player (plays).symbol) >= WIN_COUNT then
                        player (plays).win := true
                        result true
                    end if
                end if
            end for
        end for
    end for
    %%this checks grid to make sure there are still playable tiles left
    %%otherwise we have no choice to end the game!
    for row : 1 .. GRID_ROW_AMOUNT
        for colm : 1 .. GRID_COLM_AMOUNT
            if GRID (row, colm) -> is_Tile_playable = true then
                result false
            end if
        end for
    end for
    result true
end Check_for_game_win

%%this will easily switch between the player and the Comp
proc NEXT_PLAYERS_TURN
    for i : 1 .. 2
        if player (i).turn = true then
            player (i).turn := false
        else
            player (i).turn := true
        end if
    end for
end NEXT_PLAYERS_TURN
%%%%%should make random person start
if Rand.Int (1, 2) = 1 then
    NEXT_PLAYERS_TURN
end if

%%Computers AI settings, I want to make easy very random. I want to make medium challenging by setting the AI to do smart choices 50% of the time
%%and set hard to do smart choices perhaps 85% of the time.  This will make it very hard to beat hard :)
proc AI_EASY (maxRow, maxColm, plays : int)
    var randR, randC : int
    loop                                %%may have to put a better method to get these spots cause could take a while in large games.
        randR := Rand.Int (1, maxRow)
        randC := Rand.Int (1, maxColm)
        exit when GRID (randR, randC) -> is_Tile_playable = true  %%exit when random tile is found and playable
    end loop
    GRID (randR, randC) -> change_Tile_value (player (plays).symbol) %%give tile to PC
    GRID (randR, randC) -> change_Tile_playable  %%switch playability
    NEXT_PLAYERS_TURN  %%switch turns
end AI_EASY

%%This loop runs the game, it lets the user use the mouse and checks if the tiles are clicked, and user can play the game here.
loop
    cls
    Mouse.Where (mouseX, mouseY, mouseB)

    %%This will check to see when the mouse is clicked, and calls the tiles to check themselvs to see if we've been picked.
    %%IF we are then we will ofcourse change the value of that tile to the correct X or O depending on players turn.
    %%after the player sucessfully chooses a BOX, We switch to the next player.

    if player (1).turn = true then  %player 1 turn
        if mouseB = 1 then       %%waits for player to click
            for row : 1 .. GRID_ROW_AMOUNT    %%goes threw grid
                for colm : 1 .. GRID_COLM_AMOUNT
                    if GRID (row, colm) -> is_Tile_clicked (mouseX, mouseY) = true then  %%if click was on a tile
                        if GRID (row, colm) -> is_Tile_playable = true then     %%check if tile is playable
                            GRID (row, colm) -> change_Tile_value (player (1).symbol)  %%set tile to player
                            GRID (row, colm) -> change_Tile_playable         %%switch tiles playablity
                            NEXT_PLAYERS_TURN %%set to next players turn
                        end if
                    end if
                end for
            end for
            if OPTIONS -> is_Tile_clicked (mouseX, mouseY) = true then  %%options is selected
                OPTIONS_MENU  %%we bring up the options menu
            end if
        end if
        %%%player 2 is AI
    elsif player (2).turn = true then
        if Difficulty = "easy" then   %%if its easy (read AI_EASY for details)
            AI_EASY (GRID_ROW_AMOUNT, GRID_COLM_AMOUNT, 2) %%All the work is dont in AI_EASY
            %%overview: We get a spot (based on chance) and set to PC, switch playable, and switch turns.
        end if
    end if


    %%Lets draw all the tiles that exist here and maybe anything else we have to display...
    for row : 1 .. GRID_ROW_AMOUNT
        for colm : 1 .. GRID_COLM_AMOUNT
            GRID (row, colm) -> draw_Tile  %%Draw grid tiles
        end for
    end for
    for i : 1 .. 2
        if player (i).turn = true then     %%This just displays on the top which players turn it is, and their symbol
            DETAILS -> change_Tile_value ("Player " + intstr (i) + " Turn: '" + player (i).symbol + "'")
        end if
    end for
    %%draws the tiles in the BANNER (top of the screen)
    OPTIONS -> draw_Tile
    DETAILS -> draw_Tile

    exit when Check_for_game_win = true %%if games over, we exit
    View.Update
    delay (60)
end loop

put "Game Over!"
for i : 1 .. 2
    if player (i).win = true then
        put "Player ", i, ": Wins!"
    end if
end for
%Window.Close(Game_Window)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 2 Posts ]
Jump to:   


Style:  
Search: