Python Forum
Finding the treasure location
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Finding the treasure location
#1
A map is given to me in a form of this

WWWTWWWTTT
WWTTTWWWWW
WWWTWWWWWT


The treasure is located at the center of the cross of T's for which the case is (1,3)
The coordinate format is (row,column)
How do I find that exact coordinate of the treasure
Reply
#2
How do I code it in a way it will find the center of T and returns its coordinates
Reply
#3
What have you tried? We're not big on writing code for people here, but we would be happy to help you fix your code when you run into problems. When you do run into problems, please post your code in Python tags, and clearly explain the problem you are having, including the full text of any errors.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
 def find_treasure(mapfile):
    with open(mapfile,'r')as column:
        for i, row in enumerate(column):
            for j, val in enumerate(row):
                if val == 'T':
                    print(i,j) 
I can only manage to find all the coordinates for T, i dk how to set a condition such that it returns only the treasure coordinate when it is surrounded by T's
Reply
#5
Don't think about writing the code for the condition yet. Think about what the condition is. If you have a T at i, j, what other T's do you need (in terms of i and j) to be the treasure?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#6
What I am thinking is that for that specific T coordinate, i compare it to (i-1,j),(i+1,j),(i,j-1) and (i,j+1) if all those coordinates shows 'T' it means that (i,j) is the treasure location
Reply
#7
So if one condition is column[i - 1][j] == 'T', how are you going to check all four conditions?
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#8
My guess is create a list to store all the T coordinate
Then run through each of the coordinate, if (i-1,j),(i+1,j),(i,j-1) and (i,j+1) are also inside the list then return (i,j)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python - Treasure Generator on 5x5 Board PhillySports124 2 4,053 Dec-12-2017, 10:11 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020