Requoter Posted October 3, 2008 Posted October 3, 2008 I have an assignment where I'm supposed to implement a simple vacuum cleaner agent with a randomized agent function. Basically there's a world with 36 rooms in a 6 x 6 grid. The vacuum cleaner determines which square is it in and whether there is dirt in the square. It can choose to move left, move right, suck up the dirt, or do nothing. I'm new to python and I'm having really hard time to figure out what to do and how to do this. This is all I've done so far and I kind of have a mental block on what do do next. Specifically how would I implement the simulations of sucking dirt or perform the movements left, right, up, or down. If anyone can push me in the right direction I'd appreciate it. # vacuum cleaner DIRTY = '*' CLEAN = '#' NUM_ROOMS = 36 room = ['*', '*', '#', '#', '*', '#', '#', '#', '*', '*', '#', '#', '*', '#', '#', '*', '*', '*', '*', '*', '#', '#', '#', '#', '#', '#', '*', '*', '*', '#', '*', '*', '#', '#', '#', '*']
efus Posted October 6, 2008 Posted October 6, 2008 Any restrictions on how it can move trough the array? otherwise you could just go straight trough the array and check if the room is dirty or not.
Dak Posted October 6, 2008 Posted October 6, 2008 (edited) room = ['*', '*', '#', '#', '*', '#', '#', '#', '*', '*', '#', '#', '*', '#', '#', '*', '*', '*', '*', '*', '#', '#', '#', '#', '#', '#', '*', '*', '*', '#', '*', '*', '#', '#', '#', '*'] From python's point of view, that's not a 6*6 grid, that's a 36*1 grid. a 3*3 would look like this (newlines optional): room = [ ['#','#','#,'], ['#','#','#,'], ['#','#','#,'], ] or simply ['###','###','*##'], with the dirty room here being refferenced as room[2][0] (the 0th charector in the 2nd list item) every position on a 2d grid (e.g., a list of lists) can be refferenced by room[a], so i assume it'd just be a case of incrimenting/decreasing a or b to move up/down/left/right. Edited October 6, 2008 by Dak 6*6 != 32
Dave Posted October 10, 2008 Posted October 10, 2008 Almost certainly the easiest way is to use Dak's method (defining a list of strings). I should think that, in Python, a program like this would be able to be coded in a few lines.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now