Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion

[AI Competition] Dots and Boxes

AnatolyAnatoly Mod
edited August 12 in Competition Posts: 873

Want to play the game without contesting? Here's a short code to copy:

function setup()
    http.request("https://pastebin.com/raw/u5j4AS0R", function(d) loadstring(d)() setup() end, assert)
end

If you want to copy the game code and play it without internet connection, get the code here. Note! I have not implement an ending system yet, if you have issues with the code, please comment below!

Want to compete instead? Then this code is for you! Here's the start code to copy:

function setup()
    http.request("https://pastebin.com/raw/M26reBtr", function(d) loadstring(d)() setup()
        -- Edit the code below

        -- Is called when the table is changed.
        ai.on("placed", function(...)
            local args = {...}

            if #args == 4 then

            elseif #args == 6 then

            end
        end)

        -- Is called when it is your turn, no income parameters
        ai.on("turn", function()
            local x, y, v = math.random(2, 9), math.random(2, 9), math.random(0, 1)
            ai.send("place", x, y, x+v, y+1-v)
        end)

        ai.on("error", function(code, err)
            print(code, err)
        end)

        -- Edit the code above
    end, assert)
end

If you have edited the code, post it below, we'll have temporary winners: If you post better code you're as long winner till someone updates your code to be even more better!

KNOWN ISSUES

  • Calling ai.send("place", ...) more than one time in ai.on("turn") makes codea freeze. FIXED: Exit code 1
  • There is no ending feature yet.
Tagged:

Comments

  • AnatolyAnatoly Mod
    edited August 12 Posts: 873

    Events and Handlers and their Usage

    There are two functions ai.send and ai.on that are important for you: ai.on(event, callback) calls the callback function on the event call, while ai.send sends an impulse to the client that he wants to try a specific operation.

    Protocol

    • Handlers
      • placed: "box", x, y, id: Is called when a new box was placed at position (x, y) by the player id
      • placed: "line", x, y, x1, y1, id: Is called when a new line was placed at position one (x, y) and position two (x1, y1) by the player id
      • turn: Is called when it is your turn to place a line, be sure to end the callback with the event `ai.send("place", x, y, x1,y1)`
      • error: code, message: Is called when an error was recorded, returns the exit code and the readable error message
        • Error Code 0: You've tried to place a line on another line.
        • Error Code 1: It's not your turn.
    • Events
      • place: x1, y1, x2, y2 You call it when you place a line at position one (x1, y1) and position two (x2, y2)
Sign In or Register to comment.