Bottom Page

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
Quote
#2
How do I code it in a way it will find the center of T and returns its coordinates
Quote
#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

Quote
#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
Quote
#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

Quote
#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
Quote
#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

Quote
#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)
Quote

Top Page

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

Forum Jump:


Users browsing this thread: 1 Guest(s)