def __printworld__():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
def __forward__():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def __turnleft__():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def __turnright__():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def __makemove__(m):
for c in m:
if(c == "F"):
forward()
elif(c == "L"):
turnleft()
elif(c == "R"):
turnright()
def __origin__(x,y):
global px,py
px = x
py = y
world[px][py] = 1
def __test__():
origin(1,1)
mymap = "FFRFFLFFF"
makemove(mymap)
printworld()
def __joinmap__(s1,s2):
# put your code here
return s
def __main__():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
# >>> 6230032421 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def turnright():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
# put your code here
s=s1+s2
return s
def joinmap1(s1,s2):
s=s1[0:len(s1)//2]+s2[0:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
return s
def joinmap2(s1,s2):
s=""
for i in range(len(s1)):
s+=s1[i]+s2[i]
return s
def main():
# test()
origin(1,1)
s1 = "FFLLRR"
s2 = "FFFLRR"
a = joinmap(s1,s2)
b = joinmap1(s1,s2)
c = joinmap2(s1,s2)
makemove(a)
makemove(b)
makemove(c)
print(a)
printworld()
print(b)
printworld()
print(c)
printworld()
main()
# Prog-03: Treasure Hunt
# 6231001121 นายก่อพงศ์ นฤนาทดำรงค์
# โจทย์ค่อนข้างทำผมงงอยู่นาน
# ผมเป็นคนเขียนด้วยตนเองครับ
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = s1 + s2
return s
def joinmap2(s1,s2):
a = int(len(s1)/2)
sa1 = s1[:a]
sa2 = s1[a:]
b = int(len(s2)/2)
sb1 = s2[:b]
sb2 = s2[b:]
s = str(sa1 + sb1 + sa2 + sb2)
# put your code here
return s
def joinmap3(s1,s2):
a = 0
s = ""
d = int(len(s2)/2)
while a < d:
s += s1[a]+s2[a]
a += 1
s += s1[-1:]
s += s2[-3::1]
return s
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
print(s)
printworld()
s = joinmap2(s1,s2)
makemove(s)
print(s)
printworld()
s = joinmap3(s1,s2)
makemove(s)
print(s)
printworld()
main()
# >>> 6231005721 <<<
def buildmap():
global world,N
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
def reset():
global hd,px,py
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
x=(len(s1)+1)//2
y=(len(s2)+1)//2
s=s1[:x]+s2[:y]+s1[x:]+s2[y:]
return s
def joinmap3(s1,s2):
s=''
if len(s1)>len(s2):
for i in range(len(s2)):
s+=s1[i]+s2[i]
s+=s1[i+1:]
elif len(s1)<len(s2):
for i in range(len(s1)):
s+=s1[i]+s2[i]
s+=s2[i+1:]
else:
for i in range(len(s1)):
s+=s1[i]+s2[i]
return s
def main():
# test()
buildmap()
reset()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print('')
buildmap()
reset()
origin(1,1)
s = joinmap2(s1,s2)
makemove(s)
printworld()
print('')
buildmap()
reset()
origin(1,1)
s = joinmap3(s1,s2)
makemove(s)
printworld()
print('')
main()
# >>> 6231102921 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = " "
a = " "
b = " "
a = s1[:len(s1)//1] + s2[:len(s2)//4] + s1[len(s1)//7:] + s2[len(s2)//5:]
s = str(a)
for i in range (len(s1)):
b += s1[i] + s2[i]
s= a+b
return s
def main(): return __main__()
main()
# >>> 6231103521 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = " "
x = " "
y = " "
x = s1[:len(s1)//2] + s2[:len(s2)//2] + s1[len(s1)//2] + s2[:len(s2)//2:]
s = str(x)
for i in range(len(s1)):
y += s1[i] + s2[i]
s = x + y
return s
def main(): return __main__()
main()
#Prog-03
#6231109321 ณัฐภัทร ศุภรัตน์โสภิณ
#โปรแกรมนี้มีการแก้ไขคำสั่งในหลายๆจุดในคอมเมนท์---My DEV---
#โปรแกรมนี้มีการเพิ่มฟังชั่นต่างๆเช่น ค่าระดับความยาก, เพิ่มระบบหาขุมทรัพท์, ฟังชั่นรีเซ็ตแมพ, ไม่ามารถเดินได้ถ้ามีสิ่งกีดขวางข้างหน้า, รวมคำสั่งที่ใช้ซ้ำๆ ให้เป็นฟังชั่น และ อื่นๆ
#โปรแกรมนี้ยังเหลือบัคอยู่บางส่วน เช่น บางครั้งขุมทรัพย์ไม่แสดงในแผนที่ แต่โปรแกรมกับชึ้นว่าพขุมทรัพย์แล้ว เนื่องด้วยตัวนิสิตไม่่มีเวลาแก้ จึงต้องขอโทษด้วยครับบ
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd=0 # heading 0-N, 1-E, 2-S, 3-W
px=0 # current position x
py=0 # current position y
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
#---------------------------------------------------My DEV------------------------------------------
#change map from 10 to 12 for world border
N=12
world = [[0]*N for i in range(N)]
#Improve forward function
def forward():
global hd, px, py
# move one step
if(hd == 0):
if world[px][py+1] != '-':
py += 1
elif(hd == 1):
if world[px+1][py] != '-':
px += 1
elif(hd == 2):
if world[px][py-1] != '-':
py -= 1
elif(hd == 3):
if world[px-1][py] != '-':
px -= 1
if (px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
if tresure_found()==1:
world[px][py] = 'X'
else:
world[px][py] = 1
#Add world border for fix the character ran out of range
def world_border():
global world
for i in range(N-1,-1,-1):
for j in range(N):
if i==0 or i==N-1:
world[j][i]='-'
if j==0 or j==N-1:
world[j][i]='-'
#for easy output UI (makemove+printworld)
def prt(mymap,n):
global s
print('Joinmap{}\n{}'.format(n,mymap))
makemove(mymap)
printworld()
print('')
#for reset position and world map
def reset():
global hd, px, py, world
world = [[0]*N for i in range(N)]
random_obstacle()
hd,px,py=0,0,0
#change origin 0,0 to 2,2 according to map size
origin(2,2)
#generate objects"-" that block the waytrough
import random
#regenerate obstacle possiion by random
def regenerate():
global world, difficulty
world_border()
for k in range(difficulty):world[random.randint(1,10)][random.randint(1,10)]='-'
#regenerate obstacle if obstacle stacked around origin or difficulty more that 30
def random_obstacle():
global world,difficulty
regenerate()
world[2][2] = 1 if world[2][2] == '-' else 0
while world[1][2]=='-' and world[3][2]=='-' and world[2][1]=='-' and world[2][3]=='-':
regenerate()
if difficulty>30:
difficulty=30
tresure()
#genarate tresure possition
def regenerate_tresure():
global x,y
x=random.randint(1,10)
y=random.randint(1,10)
#mark tresure on wolrd map and check if tresure possition stacked into border or origin possition
def tresure():
global x,y
regenerate_tresure()
while x==1 and y==1:
regenerate_tresure()
while world[x][y]=='-':
regenerate_tresure()
world[x][y]='x'
#output if ran accross to th tresure and tresure will replace with large alphabet
def tresure_found():
if world[px][py]=='x':
print('Tresure Found!!!')
return 1
def joinmap1(s1,s2):
reset()
return str(s1)+str(s2)
def joinmap2(s1,s2):
reset()
return str(s1[0:int(len(s1)/2)])+str(s2[0:int(len(s2)/2)])+str(s1[int(len(s1)/2):])+str(s2[int(len(s2)/2):])
def joinmap3(s1,s2):
reset()
mymap=''
if s1 > s2:
mx,mn,mk=len(s1),len(s2),s1
elif s2 > s1:
mx,mn,mk=len(s2),len(s1),s2
else:
mx,mn=s1,s1
for k in range(mn):mymap+=str(s1[k])+str(s2[k])
for k in range(mx-mn):mymap+=mk[k-(mx-mn)]
return mymap
def main():
global difficulty
#Try to change data here s1,s2,difficulty
#difficulty mean number of obstacle (0-30)
difficulty=15
s1 = "FFRFRFLFFFRF"
s2 = "FFLFFRFFRFRF"
#body
print('s1={} s2={}\nDifficulty{} Tresure1'.format(s1,s2,difficulty))
print("'-'=สิ่งกีดขวาง 'x'=ขุมทรัพย์\n")
prt(joinmap1(s1,s2),1)
prt(joinmap2(s1,s2),2)
prt(joinmap3(s1,s2),3)
#---------------------------------------------------My DEV------------------------------------------
main()
# >>> 6231117321 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = " "
a = " "
b = " "
a = s1[:len(s1)//2] + s2[:len(s2)//2] + s1[len(s1)//2:] + s2[len(s2)//2:]
s = str(a)
for i in range (len(s1)):
b += s1[i] + s2[i]
s= a+b
return s
def main(): return __main__()
main()
# >>> 6231125321 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = ''
a = ''
b = ''
a = s1[:len(s1)//2] + s2[:len(s2)//2] + s1[len(s1)//2:] + s2[len(s2)//2:]
s = str(a)
for i in range(len(s1)):
b += s1[i] + s2[i]
s = a + b
return s
def main(): return __main__()
main()
# Prog-03: Treasure Hunt
# 6330005621 กรวิชญ์ ฐานะสิทธิ์
# โปรแกรมวาดเส้นทางการเดินในโลกขุมทรัพย์ที่ขยายขึ้นเป็นขนาด 15*15
# โดยมีการเขียนโค้ดเพิ่มให้ผู้ใช้ป้อนค่า s1 และ s2 ด้วยตนเอง รวมไปถึงมีการวางสิ่งกีดขวาง "X" ไว้แบบสุ่มจำนวน 20 จุดบนแผนที่ด้วย (เมื่อเดินไปเจอสิ่งกีดขวางคำสั่ง F จะไม่ทำงาน)
# อนึ่งผมขอยืนยันว่าผมเป็นผู้เขียนโปรแกรมนี้ด้วยตนเองอย่างภาคภูมิใจที่สุด
import random
N = 15 # size of world N * N
world = [[0]*N for i in range(N)]
# create obstruction
NN = 21 # obstruction count +1
obx = []
for i in range(NN):
randomNum = random.randint(0,N-1)
obx.append(randomNum)
oby = []
for i in range(NN):
randomNum = random.randint(0,N-1)
oby.append(randomNum)
for i in range(NN):
world[obx[i]][oby[i]] = "X"
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
for i in range(NN):
if(px == obx[i]) and (py == oby[i]):
py -= 1
elif(hd == 1):
px += 1
for i in range(NN):
if(px == obx[i]) and (py == oby[i]):
px -= 1
elif(hd == 2):
py -= 1
for i in range(NN):
if(px == obx[i]) and (py == oby[i]):
py += 1
elif(hd == 3):
px -= 1
for i in range(NN):
if(px == obx[i]) and (py == oby[i]):
px += 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test():
origin(7,7)
mymap = "FFRFFLFFF"
makemove(mymap)
printworld()
def joinmap1(s1,s2):
s = s1 + s2
return s
def joinmap2(s1,s2):
s1A = s1[:int(len(s1))//2]
s1B = s1[int(len(s1))//2:]
s2A = s2[:int(len(s2))//2]
s2B = s2[int(len(s2))//2:]
s = s1A + s2A + s1B + s2B
return s
def joinmap3(s1,s2):
s1List = []
s1List[:0] = s1
s2List = []
s2List[:0] = s2
n = min(int(len(s1List)), int(len(s2List)))
s = [""]*n*2
s[::2] = s1[:n]
s[1::2] = s2[:n]
s = s + s1List[n:] + s2List[n:]
return s
def main():
origin(7,3)
s1 = input("Enter s1 : ")
s2 = input("Enter s2 : ")
s = joinmap1(s1,s2)
makemove(s)
printworld()
print()
s = joinmap2(s1,s2)
makemove(s)
printworld()
print()
s = joinmap3(s1,s2)
makemove(s)
printworld()
print()
main()
# >>> 6330008521 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1 + s2
return s
def main():
# test()
origin(1,1)
s1 = "FFFRLL"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
print(s)
printworld()
main()
#oooooooooooooooooooooooooooooooooooooooooooooooooooooo
print('-----------------------------------')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[:3] + s2[2:] + s1[3:] + s2[:2]
return s
def main():
# test()
origin(1,1)
s1 = "FRFRLL"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
print(s)
printworld()
main()
()
#oooooooooooooooooooooooooooooooooooooooooooooooooooooo
print('-----------------------------------')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[0] + s2[0] + s1[1] + s2[1] + s1[2] + s2[2] + s1[3] + s2[3] + s1[4] + s2[4] + s1[5] + s2[5]
return s
def main():
# test()
origin(1,1)
s1 = "FRFRLL"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
print(s)
printworld()
main()
()
#oooooooooooooooooooooooooooooooooooooooooooooooooooooo
print('-----------------------------------')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[::-1] + s2[::-1]
return s
def main():
# test()
origin(1,1)
s1 = "FRFRLL"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
print(s)
printworld()
main()
# code นี้มี function สำหรับ encode decode โดยใช้ algorithm ที่ชื่อว่า encode and decode poom
# code นี้มี algorithm เมื่อพบสิ่งกีดขวาง และสิ่งกีดขวามผมได้ตั้งให้เป็นเลข 3 หมายเหตุ มีตารางให้ทดสอบ ทำ comment ไว้ครับ
# ผม set default ของ origin ไว้ที่ (0,0)
# 6330009121 กฤตเมธ แก้วชื่น
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# For testing when facing the wall
''' world = [ [0, 0, 3, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 3, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 3, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0] ] '''
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
if world[px][py] == 3: # When meet the wall
py -= 1
elif(hd == 1):
px += 1
if world[px][py] == 3: # When meet the wall
px -= 1
elif(hd == 2):
py -= 1
if world[px][py] == 3: # When meet the wall
py += 1
elif(hd == 3):
px -= 1
if world[px][py] == 3: # When meet the wall
px += 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
return s1+s2
def joinmap2(s1,s2):
return s1[:int(len(s1)/2)] + s2[:int(len(s2)/2)] + s1[int(len(s1)/2):] + s2[int(len(s2)/2):]
def joinmap3(s1,s2):
s = ''
for i in range(len(s1)):
s = s + s1[i] +s2[i]
return s
# for encode
def encode_poom_algo(text,key):
encode_text = str(len(key))
for i in key:
encode_text += chr(ord(i)+3)
for i in text:
encode_text += chr(ord(i)+2)
return encode_text
# for decode
def decode_poom_algo(text,key):
check_key = ""
result = ""
for i in range(int(text[0])):
check_key += chr(ord(text[i+1])-3)
if check_key == key:
for i in range(len(text)-len(key)-1):
result += chr(ord(text[len(key)+1+i])-2)
return result
else:
return False
def main():
# test()
origin(0,0)
s1 = "FFFLLL"
s2 = "FFRRFF"
# encode and decode
s1 = encode_poom_algo(s1,"pp")
s2 = encode_poom_algo(s2,"pp")
s1 = decode_poom_algo(s1,"pp")
s2 = decode_poom_algo(s2,"pp")
s = joinmap1(s1,s2)
#s = joinmap2(s1,s2)
#s = joinmap3(s1,s2)
print(s)
makemove(s)
printworld()
main()
# Prog-03: Treasure Hunt
# 6330014221 กษมวัต จงพิพัฒน์วณิชย์
# ผมได้เขียนโปรแกรมนี้ด้วยตนเองครับ
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
L1=len(s1)//2
L2=len(s2)//2
x=0
y=0
s=""
while x<=len(s1):
s12=s1[x:x+L1]
s22=s2[y:y+L2]
s=s+s12+s22
x=x+L1
y=y+L2
return s
def joinmap3(s1,s2):
x=0
y=0
s=""
while x<=len(s1):
s12=s1[x:x+2]
s22=s2[y:y+2]
s=s+s12+s22
x=x+2
y=y+2
return s
def main():
# test()
origin(1,1)
if walk==1:
s = joinmap1(s1,s2)
elif walk==2:
s = joinmap2(s1,s2)
elif walk==3:
s = joinmap3(s1,s2)
makemove(s)
print("This is how you walk :",s)
printworld()
walk=int(input("Please type walking type (1,2,3) > "))
if 0<walk<4:
s1=str(input("Please type walking 1 > "))
s2=str(input("Please type walking 2 > "))
main()
else:
print("Please type 1 or 2 or 3")
# >>> 6330016521 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def joinmap(s1,s2): #1
s = s1+s2
return s
def main():
# test()
origin(1,1)
s1 = "FFRF"
s2 = "FLFR"
s = joinmap(s1,s2)
makemove(s)
def joinmap(s1,s2): #2
s = s1[0:2]+s2[0:2]+s1[2:]+s2[2:]
return s
def main():
# test()
origin(1,1)
s1 = "FFRF"
s2 = "FLFR"
s = joinmap(s1,s2)
makemove(s)
def joinmap(s1,s2): #3
s = s1[0]+s2[0]+s1[1]+s2[1]+s1[2]+s2[2]+s1[3]+s2[3]
return s
def main():
# test()
origin(1,1)
s1 = "FFRF"
s2 = "FLFR"
s = joinmap(s1,s2)
makemove(s)
# >>> 6330021621 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
# put your code here
s = s1 + s2
return s
def joinmap2(s1,s2):
# put your code here
s = s1[:3] + s2[:3] + s1[3:] + s2[3:]
return s
def joinmap3(s1,s2):
# put your code here
s = s1[0] + s2[0] + s1[1] + s2[1] + s1[2] + s2[2] + s1[3] + s2[3] + s1[4] + s2[4] + s1[5] + s2[5]
return s
def main1():
# test()
origin(1,1)
s1 = "FFRFFF"
s2 = "LFRFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
def main2():
# test()
origin(1,1)
s1 = "FFRFFF"
s2 = "LFRFLF"
s = joinmap2(s1,s2)
makemove(s)
printworld()
def main3():
# test()
origin(1,1)
s1 = "FFRFFF"
s2 = "LFRFLF"
s = joinmap3(s1,s2)
makemove(s)
printworld()
main1()
print("\n")
main2()
print("\n")
main3()
# >>> 6330022221 <<<
import random
def buildmap():
global world,N
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
def reset():
global hd,px,py
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
mem1=px
mem2=py
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
if world[px][py]==9:
px,py=mem1,mem2
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
x=(len(s1)+1)//2
y=(len(s2)+1)//2
s=s1[:x]+s2[:y]+s1[x:]+s2[y:]
return s
def joinmap3(s1,s2):
s=''
if len(s1)>len(s2):
for i in range(len(s2)):
s+=s1[i]+s2[i]
s+=s1[i+1:]
elif len(s1)<len(s2):
for i in range(len(s1)):
s+=s1[i]+s2[i]
s+=s2[i+1:]
else:
for i in range(len(s1)):
s+=s1[i]+s2[i]
return s
def special():
for i in range(5):
t1=random.randint(0,N-1)
t2=random.randint(0,N-1)
while t1==1:
t1=random.randint(0,N-1)
while t2==1:
t2=random.randint(0,N-1)
world[t1][t2]=9
def main():
# test()
buildmap()
reset()
special()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print('')
buildmap()
reset()
special()
origin(1,1)
s = joinmap2(s1,s2)
makemove(s)
printworld()
print('')
buildmap()
reset()
special()
origin(1,1)
s = joinmap3(s1,s2)
makemove(s)
printworld()
print('')
main()
# >>> 6330028021 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
def resetworld():
world = [[0] * N for i in range(N)]
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
s= s1[:int(len(s1))//2] + s2[:int(len(s2))//2] + s1[int(len(s1))//2:] + s2[int(len(s1))//2:]
return s
def joinmap3(s1,s2):
s=""
for i in range(len(s1)+len(s2)):
s = s + s1[i:i + 1]
s = s + s2[i:i + 1]
return s
def main():
global world
# test()
print("Map 1\n")
origin(1,1)
s1 = "FFFFFFRL"
s2 = "RRLLLRFF"
s = joinmap1(s1,s2)
# print(s)
makemove(s)
printworld()
print("\n--------------------\n")
world = [[0] * N for i in range(N)]
origin(1, 1)
s1 = "FFFFFFRL"
s2 = "RRLLLRFF"
s = joinmap2(s1, s2)
# print(s)
makemove(s)
printworld()
print("\n--------------------\n")
world = [[0] * N for i in range(N)]
origin(1, 1)
s1 = "FFFFFFRL"
s2 = "RRLLLRFF"
s = joinmap3(s1, s2)
# print(s)
makemove(s)
printworld()
print("\n--------------------\n")
main()
# >>> 6330030221 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = s1 + s2
return s
def joinmap2(s1,s2):
x1 = list(s1)
x2 = list(s2)
y = x1[0:len(x1)//2] + x2[0:len(x2)//2] + x1[len(x1)//2:] + x2[len(x2)//2:]
return y
def joinmap3(s1,s2):
x1 = []
x2 = []
x1[:0] = s1
x2[:0] = s2
m = min(len(x1), len(x2))
y = [""]*m*2
y[::2] = x1[:m]
y[1::2] = x2[:m]
y = y + x1[m:] + x2[m:]
return y
def main():
# test()
origin(6,2)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
s = joinmap2(s1,s2)
makemove(s)
printworld()
s = joinmap3(s1,s2)
makemove(s)
printworld()
main()
# >>> 6330034821 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld():
for i in range(N-1,-1,-1):
for j in range(N):
#Treasure Point
world[0][3] = "∆"
#Blocking
for k in range(8):
world[k][2] = "x"
for m in range(6):
world[1][m+4] = "x"
world[3][m+3] = "x"
world[5][m+4] = "x"
world[7][m+3] = "x"
print(world[j][i], end = " ")
print()
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = s1 + s2
return s
def joinmap2(s1,s2):
n1 = int(len(s1)/2)
n2 = int(len(s2)/2)
s = s1[0:n1] + s2[0:n2] + s1[n1:] + s2[n2:]
return s
def joinmap3(s1,s2):
n1 = len(s1)
n2 = len(s2)
n = max(n1,n2)
s = ""
for i in range(n):
s += s1[i] + s2[i]
return s
def main():
origin(1,1)
#1st join piece of s1,s2
s1 = "RFFFFFFF"
s2 = "LFFFFFFF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
#2nd split s1,s2 to half then mix it together
s1 = "FLFFFFFR"
s2 = "LFFFFFRF"
s = joinmap2(s1,s2)
makemove(s)
printworld()
#3rd mix a single piece from each cmd respectively
s1 = "FFFFLFFFF"
s2 = "FFLFFFFRR"
s = joinmap3(s1,s2)
makemove(s)
printworld()
main()
#Prog-03:Treasure Hunt
#6330043421 คณิน งามปฏิพัทธ์พงศ์
#ผมเป็นคนเขียนส่วนjoinmapด้วยตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s3=s1+s2
s=[]
s[:]=s3
return s
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFRF"
s = joinmap(s1,s2)
makemove(s)
printworld()
print("-"*2*N)
main()
N = 10 # size of world N * N
world = [[0] * N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld2():
for i in range(N - 1, -1, -1):
for j in range(N):
print(world[j][i], end=" ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward2():
global hd, px, py
# move one step
if (hd == 0):
py += 1
elif (hd == 1):
px += 1
elif (hd == 2):
py -= 1
elif (hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if (px > N - 1):
px = N - 1
if (px < 0):
px = 0
if (py > N - 1):
py = N - 1
if (py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft2():
global hd
hd -= 1
if (hd < 0):
hd = 3
# turn head right 90 degree
def turnright2():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove2(m):
for c in m:
if (c == "F"):
forward()
elif (c == "L"):
turnleft()
elif (c == "R"):
turnright()
def origin2(x, y):
global px, py
px = x
py = y
world[px][py] = 1
def joinmap2(s1,s2):
b=[]
s3=s1[:len(s1)//2]+s2[:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
b[:]=s3
return b
def main2():
# test()
origin2(1,1)
s1 = "FFFR"
s2 = "FFLFRF"
b = joinmap2(s1,s2)
makemove2(b)
printworld2()
print("-"*2*N)
main2()
N = 10 # size of world N * N
world = [[0] * N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld1():
for i in range(N - 1, -1, -1):
for j in range(N):
print(world[j][i], end=" ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward1():
global hd, px, py
# move one step
if (hd == 0):
py += 1
elif (hd == 1):
px += 1
elif (hd == 2):
py -= 1
elif (hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if (px > N - 1):
px = N - 1
if (px < 0):
px = 0
if (py > N - 1):
py = N - 1
if (py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft1():
global hd
hd -= 1
if (hd < 0):
hd = 3
# turn head right 90 degree
def turnright1():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove1(m):
for c in m:
if (c == "F"):
forward()
elif (c == "L"):
turnleft()
elif (c == "R"):
turnright()
def origin1(x, y):
global px, py
px = x
py = y
world[px][py] = 1
def joinmap1(s1,s2):
y=[]
y[:]=s1
z=[]
z[:]=s2
a=[]
if len(y)>len(z):
for i in range(len(y)-len(z)):
z+=["h"]
elif len(y)<len(z):
for i in range(len(z)-len(y)):
y+=["h"]
for t in range(len(y)):
a.append(y[t])
a.append(z[t])
return a
def main1():
# test()
origin1(1,1)
s1 = "FFFR"
s2 = "FFLFRF"
a = joinmap1(s1,s2)
makemove1(a)
printworld1()
print("-"*2*N)
main1()
# Prog-03: Treasure Hunt
# 6330047021 คุณานนต์ ศุภศิริ
# ผมได้ทำการใส่รหัสลับเหนือจินตนาการเข้าไป ทำให้การหาสมบัติในครั้งนี้มีความตื่นเต้นมากกว่าครั้งใดในโลก
# ผมได้ออกแบบและพัฒนาโปรแกรมนี้ด้วยตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2): # 1.คำสั่งถูกแยกเป็นสองชิ้น จับมันมาต่อกัน
s = s1 + s2
return s
def joinmap2(a1,a2): # 2.คำสั่งมีสองชิ้น แต่ละชิ้นถูกแบ่งครึ่ง การต่อเข้าด้วยกัน ให้สลับชิ้นส่วนกับแผ่นอื่น
a = a1[:int(len(a1)/2)] + a2[:int(len(a2)/2)] + a1[int(len(a1)/2):] + a2[int(len(a2)/2):]
return a
def joinmap3(b1,b2): # 3.คำสั่งมีสองชิ้น เวลามาต่อกันให้สลับอักขระสองชิ้นเข้าด้วยกันทีละตัว
b = ""
for i in range(int(len(b1))):
b = b + b1[i]
b = b + b2[i]
return b
def joinmap4(c1,c2): # Function นอกเหนือโจทย์
c = c1 + c2
return c
def translator(c1): # Function พิเศษเพื่อถอดรหัสจากตัวเลขเป็นตัวอักษร
ct1 = ""
for i in range(int(len(c1))):
if c1[i] == "1" :
ct1 += "F"
elif c1[i] == "2" :
ct1 += "R"
elif c1[i] == "3" :
ct1 += "L"
return ct1
def translator(c2): # Function พิเศษเพื่อถอดรหัสจากตัวเลขเป็นตัวอักษร
ct2 = ""
for i in range(int(len(c2))):
if c2[i] == "1" :
ct2 += "F"
elif c2[i] == "2" :
ct2 += "R"
elif c2[i] == "3" :
ct2 += "L"
return ct2
def main():
origin(4,0)
print ('\033[1m' + 'FIRST MOVE ' + '(FFF)')
s1 = "FF"
s2 = "F"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print ('\033[1m' + 'SECOND MOVE ' + '(FLFFRFFFF)')
a1 = "FLRF"
a2 = "FFFFF"
a = joinmap2(a1,a2)
makemove(a)
printworld()
print ('\033[1m' + 'THIRD MOVE ' + '(RFFFFFRF)')
b1 = "RFFR"
b2 = "FFFF"
b = joinmap3(b1,b2)
makemove(b)
printworld()
print ('\033[1m' + 'FINAL MOVE ' + '(1121121 = FFRFFRF)')
c1 = "1121"
c2 = "121"
tr1 = translator(c1)
tr2 = translator(c2)
c = joinmap4(tr1,tr2)
makemove(c)
printworld()
print("Congratulations!!! You've found the TREASURE!!!!!!")
main()
# Prog-03: Treasure Hunt
# 6330050821 จักราวุธ กรรณสูต
# เนื่องจากโปรแกรมนี้มี3ฟังก์ชัน และนิสิตยังไม่มีความรู้ในการทำให้โปรแกรมรันทั้ง3ตัวภายใน1ครั้งได้ จึงต้องทำการเปลี่ยนตัวแปรเล็กน้อยและรันทีละครั้ง เพื่อใช้งานฟังก์ชันทั้ง3ตัว (วิธีอยู่ด้านล่าง)
# ในฟังก์ชันที่3 นิสิตได้ประยุกต์คำสั่งมาใช้sliceแทนที่index เนื่องจากจะอ่านค่าอักขระเกินrangeของค่าที่มีอยู่ได้ แต่จะมีข้อจำกัดคือ ไม่สามารถอ่านเกินกว่าค่าที่ตั้งไว้ถึงได้ ในกรณีนี้คือ6ตัว
# ผมขอยืนยันว่าทำการเขียนโปรแกรมทั้งสามฟังก์ชันด้วยฝีมือของตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2): #วิธีใช้: เปลี่ยนชื่อฟังก์ชันที่ต้องการrunให้เป็น s แล้วกดrun
first_s=s1+s2 #first type
second_s=s1[:int(len(s1)/2):]+s2[:int(len(s2)/2):]+s1[int(len(s1)/2)::]+s2[int(len(s2)/2)::] #second type
third_s=s1[0:1]+s2[0:1]+s1[1:2]+s2[1:2]+s1[2:3]+s2[2:3]+s1[3:4]+s2[3:4]+s1[4:5]+s2[4:5]+s1[5:6]+s2[5:6]+s1[6:7]+s2[6:7] #third type(ใช้sliceแทนindexเพราะสามารถตั้งให้เกินrangeได้ แต่ข้อจำกัดคือจะอ่านได้ถึงแค่จำนวนเลขที่เขียนถึง กรณีนี้คือ6ตัว)
return s
def main():
# test()
origin(1,1)
s1 = "FFRF"
s2 = "FRFFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
print(s) #นิสิตใส่เพิ่มเพื่อตรวจสอบอักขระคำสั่งว่าเรียงถูกต้อง
main()
# >>> 6330051421 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s=s1+s2
return s
def joinmap1(s1,s2):
s=s1[:(len(s1)//2)]+s2[:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
return s
def joinmap2(s1,s2):
s=""
for i in range(0,len(s1)) :
s+=s1[i:i+1]+s2[i:i+1]
return s
def main():
global world
# test()
origin(1,1)
s1 = "FFLL"
s2 = "RRFFFF"
s = joinmap(s1,s2)
makemove(s)
printworld()
print("\n")
world = [[0] * N for i in range(N)]
origin(1, 1)
s1 = "FFFF"
s2 = "RRLL"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print('\n')
world = [[0] * N for i in range(N)]
origin(1, 1)
s1 = "FFFF"
s2 = "RLRL"
s = joinmap2(s1,s2)
makemove(s)
printworld()
main()
# >>> 6330055021 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
print("#FFFRFFLFLF")
def joinmap1(s1,s2):
s1="FFFR"
s2="FFLFLF"
s=s1+s2
return s
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
main()
print("")
print("#RFFFLFRFFFRFFFLF")
def joinmap2(s1,s2):
s1="RFFFFFRF"
s2="LFRFFFLF"
s=s1[0:4]+s2[0:4]+s1[4:8]+s2[4:8]
return s
def main():
# test()
origin(1,1)
s1 = "RFFFLFFF"
s2 = "LFRFFFLF"
s = joinmap2(s1,s2)
makemove(s)
printworld()
main()
print("")
print("#FRFFFLFFRFFF")
def joinmap2(s1,s2):
s1="FFFFRF"
s2="RFLFFF"
s=s1[0]+s2[0]+s1[1]+s2[2]+s1[3]+s2[3]+s1[4]+s2[4]+s1[5]+s2[5]
return s
def main():
# test()
origin(1,1)
s1 = "FFFFRF"
s2 = "RFLFFF"
s = joinmap2(s1,s2)
makemove(s)
printworld()
main()
# >>> 6330064621 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
if obstacle(px,py):
py -= 1
elif(hd == 1):
px += 1
if obstacle(px,py):
px -= 1
elif(hd == 2):
py -= 1
if obstacle(px,py):
py += 1
elif(hd == 3):
px -= 1
if obstacle(px,py):
px += 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
#งานแบบที่1
def joinmap1(s1,s2):
# put your code here
s = s1+s2
return s
#งานแบบที่2
def joinmap2(s1,s2):
s = s1[:len(s1)//2]+s2[:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
return s
#งานแบบที่3
def joinmap3(s1,s2):
s = ""
for i in range(len(s1)):
s += s1[i]
s += s2[i]
return s
#สิ่งกีดขวางที่มองไม่เห็น ขนาด 3x2 เมื่อเดินชนจะไปต่อไม่ได้จะต้องเดินเลาะไป(งานเพิ่มเติม)
def obstacle(x,y):
if (x>=2 and x<=4) and (y>=4 and y<=5):
return True
else:
return False
def main():
# test()
origin(1,1)
#งานแบบที่1
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print()
#งานแบบที่2
s1 = "RFRF"
s2 = "FLFFRLFF"
s = joinmap2(s1,s2)
makemove(s)
printworld()
print()
#งานแบบที่3
s1 = "FRFFRLF"
s2 = "RFLFFLF"
s = joinmap3(s1,s2)
makemove(s)
printworld()
print()
main()
#Prog-3:Treasure Hunt
#6330068121 ชญาดา สุทธิทศธรรม
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
a=s1+s2
return a
def joinmap2(s1,s2):
b=s1[0:len(s1)//2]+s2[0:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
return b
def joinmap3(s1,s2):
c=[]
c[:0]=s1
d=[]
d[:0]=s2
mi=min(len(c),len(d))
e=[""]*2*mi
e[::2]=c[:mi]
e[1::2]=d[:mi]
e=e+c[mi:]+d[mi:]
return e
def main():
# test()
origin(6,4)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
print()
t=joinmap2(s1,s2)
makemove(t)
printworld()
print()
u=joinmap3(s1,s2)
makemove(u)
printworld()
print()
main()
# Prog-03: Treasure Hunt
# 6330069821 ชญานนท์ โชติวานิช
# เขียนด้วยตัวเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test1():
origin(1,1)
mymap = "FFRFFLFFF"
makemove(mymap)
printworld()
def joinmap1(s1,s2):
s =s1+s2
return s
def main1():
# test()
origin(5,1)
s1 = "FFFLLLRRR"
s2 = "FFRRFFLL"
s = joinmap1(s1,s2)
makemove(s)
printworld()
main1()
def test2():
origin(1,1)
mymap = "FFRFFLFFF"
makemove(mymap)
printworld()
def joinmap2(s1,s2):
s = s1[0:2] +s2[0:2] +s1[2:4]+s2[2:4]+s1[4:6]+s2[4:6]+s1[6:8]+s2[6:8]+s1[8:]+s2[8:]
return s
def main2():
# test()
origin(5,1)
s1 = "FFFLLLRRLFLF"
s2 = "FFRRFFLRFFFL"
s = joinmap2(s1,s2)
makemove(s)
printworld()
main2()
def test3():
origin(1,1)
mymap = "FFRFFLFFFFRFFLFF"
makemove(mymap)
printworld()
def joinmap3(s1,s2):
s = s1[0]+s2[0]+s1[1]+s2[1]+s1[2]+s2[4]+s1[3]+s2[5]+s1[4]+s2[2]+s1[5]+s2[3]
return s
def main3():
# test()
origin(1,1)
s1 = "FRFLFL"
s2 = "FFFRRF"
s = joinmap3(s1,s2)
makemove(s)
printworld()
main3()
#------------------------end------------------
# >>> 6330074921 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[::] + s2[::]
# put your code here
return s
def main():
# test()
origin(1,1)
s1 = "FRFRL"
s2 = "FFRLLF"
s = joinmap(s1,s2)
makemove(s)
print(s)
print("")
printworld()
print("")
main()
#---------------------------------------end--------------------------------
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[:2:] + s2[:2:] + s1[2:4] + s2[2:4] + s1[4:6]
# put your code here
return s
def main():
# test()
origin(1,1)
s1 = "FRFRRF"
s2 = "FFRL"
s = joinmap(s1,s2)
makemove(s)
print(s)
print("")
printworld()
print("")
main()
#------------------------------------end----------------------------
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1[0] + s2[0] + s1[1] + s2[1]+s1[2] + s2[2] + s1[3] + s2[3]
# put your code here
return s
def main():
# test()
origin(1,1)
s1 = "FRFR"
s2 = "LFLR"
s = joinmap(s1,s2)
makemove(s)
print(s)
print("")
printworld()
main()
#---------------------------------end----------------------------------
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
if s1[-1] or s2[-1] == "A":
s1 = s1[:-1:] + "RF"
s2 = s2[:-1:] + "LF"
if s1[-1] or s2[-1] == "B":
s2 = s2[-1::-1] + "RF"
s1 = s1[-1::-1] + "LF"
s = s1[::] + s2[::]
# put your code here
return s
def main():
# test()
origin(1,1)
s1 = "FFFRA"
s2 = "FFLFLFB"
s = joinmap(s1,s2)
makemove(s)
print("")
print(s)
print("")
printworld()
main()
#-------------------------------------end-----------------------------
#Prog-01: treasure hunt
#6330084121 ชนุตร ช่วยดำรงค์
#-
#-
#ทำเองเเน่นอนครับ ทำนานมากเลยครับยากมากไม่ไหวเเล้วครับ
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = s1+s2
return s
def joinmap2(s1,s2):
ss = s1[0:len(s1)//2] + s2[0:len(s2)//2] + s1[len(s1)//2::] +s2[len(s2)//2::]
return ss
def joinmap3(s1,s2):
s11 = []
s11[:0] = s1
s21 = []
s21[:0] = s2
minn = min(len(s11),len(s21))
mek = ['']*2*minn
mek[::2] = s11[:minn]
mek[1::2] = s21[:minn]
mek = mek + s11[minn:] + s21[minn:]
return mek
def main():
# test()
origin(6,4)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
print()
ss = joinmap2(s1,s2)
makemove(ss)
printworld()
print()
sss = joinmap3(s1,s2)
makemove(sss)
printworld()
main()
# >>> 6330101121 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def joinmap(s1,s2):
# put your code here
s = s1 + s2
s = s1[:3] + s2[:3] + s1[3:] + s2[3:]
s = s1[0:1] + s2[0:1] + s1[1:2] + s2[1:2] + s1[2:3] +s2[2:3]
return s
def main():
origin(1,1)
s1 = "FFFRRR"
s2 = "FFLLFF"
s = joinmap(s1,s2)
makemove(s)
printworld()
main()
#6330104021 ชาญกิจ สุขสุวรรณวีรี
#โปรแกรมนี้มีการแปลรหัสลับให้กลายเป็นตัวอักษรก่อนที่จะเริ่มเดิน
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def decode(s1,s2):
d1=s1.split(".")
d2=s2.split(".")
Char=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
for i in range(len(d1)):
d1[i]=Char[(2626-int(d1[i]))//100]
for i in range(len(d2)):
d2[i]=Char[(2626-int(d2[i]))//100]
return d1,d2
def joinmap1(s1,s2):
# put your code here
s=s1+s2
return s
def joinmap2(s1,s2):
# put your code here
s=s1[0:int(len(s1)/2)]+s2[0:int(len(s2)/2)]+s1[int(len(s1)/2):int(len(s1))]+s2[int(len(s2)/2):int(len(s2))]
#print(s)
return s
def joinmap3(s1,s2):
# put your code here
s=[ ]
for i in range(len(s1)):
s+=s1[i]+s2[i]
return s
def main():
# test()
origin(1,1)
#***************************************************
s1 = "2126.2126.2126.2126.2126.2126" #FFFFFF
s2 = "1526.2126.0926.2126.0926.2126" #LFRFRF
s1,s2=decode(s1,s2)
#***************************************************
s = joinmap1(s1,s2)
#print(s)
makemove(s)
printworld()
print("\n")
#---------------------------------------------
#print(s1,s2)
s = joinmap2(s1,s2) #FFFLFRFFFFRF
#print(len(s1),len(s2))
#print(s)
makemove(s)
printworld()
print("\n")
#-------------------------------------------------
s = joinmap3(s1,s2) #FLFFFRFFFRFF
#print(len(s1),len(s2))
#print(s)
makemove(s)
printworld()
#-------------------------------------------------
main()
# >>> 6330105721 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
# put your code here
s = s1+s2
print(s)
return s
def joinmap1(f1,f2):
# put your code here
f = f1[:int(len(f1)/2):]+f2[:int(len(f2)/2):]\
+f1[int(len(f1)/2):]+f2[int(len(f2)/2):]
print(f)
return f
def joinmap2(d1,d2):
# put your code here
ss1=list(d1)
ss2=list(d2)
d = ss1[0]+ss2[0]+ss1[1]+ss2[1]+ss1[2]+ss2[2]\
+ss1[3]+ss2[3]+ss2[4]+ss2[5]
print(d)
return d
def main(): return __main__()
def main1():
# test()
origin(1,1)
f1 = "FFFR"
f2 = "FFLFLF"
f = joinmap1(f1,f2)
makemove(f)
printworld()
def main2():
# test()
origin(1,1)
d1 = "FFFR"
d2 = "FFLFLF"
d = joinmap2(d1,d2)
makemove(d)
printworld()
main()
main1()
main2()
# Prog-03: Treasure Hunt
# 6330129821 ณฐกร โมลา
# โปรแกรมนี้ใช้สำหรับเกมล่าขุมทรัพย์โดยเป็นตารางแบบ 10*10
# ขอยืนยันว่านิสิตเป็นผู้เขียนโปรแกรมนี้ด้วยตนเองและเขียนอย่างสุดความสามารถ
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
# put your code here
s=s1+s2
return s
def joinmap2(s1,s2):
# put your code here
s1_f = s1[:len(s1)//2]
s1_b = s1[len(s1)//2:]
s2_f = s2[:len(s2)//2]
s2_b = s2[len(s2)//2:]
s = s1_f+s2_f+s1_b+s2_b
return s
def joinmap3(s1,s2):
# put your code here
s11 = s1[:min(len(s1),len(s2)):]
s22 = s2[:min(len(s1),len(s2)):]
s1_1=s11[::2]
s1_2=s11[1::2]
s2_1=s22[::2]
s2_2=s22[1::2]
s3=(s1_1+s2_1+s1_2+s2_2)[::2]
s4=(s1_1+s2_1+s1_2+s2_2)[1::2]
s5=(s3+s4)
s6=s1[min(len(s1),len(s2)):]
s7=s2[min(len(s1),len(s2)):]
s8=s5+s6+s7
s=s8
return s
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
print("joinmap1")
printworld()
s = joinmap2(s1,s2)
makemove(s)
print("joinmap2")
printworld()
s = joinmap3(s1,s2)
makemove(s)
print("joinmap3")
printworld()
main()
# >>> 6330132621 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld():
for i in range(N-1,-1,-1):
for j in range(N):
if(world[j][i]==0):print('\033[0m'+str(world[j][i]), end = " ")
else:print('\033[91m'+str(world[j][i]), end = " ")
# print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
# put your code here
s=s1+s2
s=s+s1[:len(s1)//2]+s2[:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
for i in range(len(s1)):
s=s+s1[i]+s2[i]
return s
def joinmap1(s1,s2):return s1+s2
def joinmap2(s1,s2):return s1[:len(s1)//2]+s2[:len(s2)//2]+s1[len(s1)//2:]+s2[len(s2)//2:]
def joinmap3(s1,s2):
s=''
if len(s1)< len(s2):
mn=len(s1)
se=s2[len(s1):]
else:
mn=len(s2)
se=s1[len(s2):]
for i in range(mn):
s=s+s1[i]+s2[i]
return s+se
def main(): return __main__()
main()
print('')
def b4():
global world
world = [[0]*N for i in range(N)]
origin(1,1)
global hd
hd=0
def aftr(s):
print(s)
makemove(s)
printworld()
def main123():
s1 = "FFFRLFLFFFFFF"
s2 = "FFLFLFLRFLFLF"
b4()
s = joinmap1(s1,s2)
print('\033[92m'+'Joinmap1:'+s+'\033[0m')
aftr(s)
b4()
s = joinmap2(s1,s2)
print('\033[93m'+'Joinmap2:'+s+'\033[0m')
aftr(s)
b4()
s = joinmap3(s1,s2)
print('\033[94m'+'Joinmap3:'+s+'\033[0m')
aftr(s)
main123()
# Prog-03: Treasure Hunt
# 6330141221 ณภัทร นิลพฤกษ์
# โปรแกรมนี้ออกแบบลายแทงขุมทรัพย์ที่ซับซ้อนและงุนงง
# ผมขอยืนยันว่าผมเป็นผู้เขียนโปรแกรมนี้ด้วยตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = s1 + s2
return s
def joinmap2(s1,s2):
s = s1[:4]+s2[:4]+s1[4:]+s2[4:]
return s
def joinmap3(s1,s2):
s = s1[0]+s2[0]+s1[1]+s2[1]+s1[2]+s2[2]+s1[3]+s2[3]+\
s1[4]+s2[4]+s1[5]+s2[5]+s1[6]+s2[6]+s1[7]+s2[7]
return s
def main():
global world
# test()
print(" Treasure Map 1\n")
origin(1,1)
s1 = "RFFLFFRF"
s2 = "LRFFRFLF"
s = joinmap1(s1,s2)
#print(s)
makemove(s)
printworld()
makemove(s)
makemove(s)
makemove(s)
print("\n*********************\n")
world = [[0]*N for i in range(N)]
print(" Treasure Map 2\n")
origin(1,1)
s1 = "RFFLFFRF"
s2 = "LRFFRFLF"
s = joinmap2(s1,s2)
#print(s)
makemove(s)
printworld()
makemove(s)
makemove(s)
makemove(s)
print("\n*********************\n")
world = [[0]*N for i in range(N)]
print(" Treasure Map 3\n")
origin(1,1)
s1 = "RFFLFFRF"
s2 = "LRFFRFLF"
s = joinmap3(s1,s2)
#print(s)
makemove(s)
printworld()
print("\n*********************\n")
main()
# >>> 6330160121 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(a,b):
# put your code here
s = a+b
return s
def joinmap1(a,b):
s = a[:len(a)//2]+b[:len(b)//2]+a[len(a)//2:]+b[len(b)//2:]
return s
def joinmap2(a,b):
s =""
for i in range(len(a)):
s += a[i]+b[i]
return s
def translation(s1,s2): #ฟังก์ชั่นในการแปลรหัสก่อน
a =""
for e in s1:
if e in "FLR" :
a += e
b =""
for e in s2:
if e in "FLR":
b += e
return a,b
def main():
# test()
origin(1,1)
s1 = "ASFsadFFdsRFaFd"#มีรหัสลับในคำสั่งต้องทำการแปลรหัสด้วย เพื่อไม่ให้หาสมบัติเจอง่ายไป
s2 = "FFsadLFLasFdsa"
a,b = translation(s1,s2)
s = joinmap(a,b)
makemove(s)
printworld()
def main1():
# test()
origin(1,1)
s1 = "ASFsadFFdsRFaFd"#มีรหัสลับในคำสั่งต้องทำการแปลรหัสด้วย เพื่อไม่ให้หาสมบัติเจอง่ายไป
s2 = "FFsadLFLasFdsa"
a,b = translation(s1,s2)
s = joinmap1(a,b)
makemove(s)
printworld()
def main2():
# test()
origin(1,1)
s1 = "ASFsadFFdsRFaFd"#มีรหัสลับในคำสั่งต้องทำการแปลรหัสด้วย เพื่อไม่ให้หาสมบัติเจอง่ายไป
s2 = "FFsadLFLasFdsa"
a,b = translation(s1,s2)
s = joinmap2(a,b)
makemove(s)
printworld()
print("joinmap")
main()
print("")
print("joinmap1")
main1()
print("")
print("joinmap2")
main2()
print("")
# >>> 6330196821 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
# put your code here
s1 = "RFFFFFFL"
s2 = "FFFFFFF"
s = s1+s2
return s
def joinmap2(a1,a2):
a1 = "RFFLFF"
a2 = "FFFFFFF"
a = a1[0:3]+a2[0:3]+a1[3:]+a2[3:]
return a
def joinmap3(b1,b2):
b1 = "FFFFFFFFF"
b2 = "FFFFLFFFF"
b = b1[0]+b2[0]+b1[1]+b2[1]+b1[2]+b2[2]+b1[3]+b2[3]+b1[4]+b2[4]+b1[5]+b2[5]+b1[6]+b2[6]+b1[7]+b2[7]+b1[8]+b2[8]
return b
def main():
# test()
origin(0,0)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
main()
print('')
def main():
origin(0,1)
a1 = "RFFLFF"
a2 = "FFFFFFF"
a = joinmap2(a1,a2)
makemove(a)
printworld()
main()
print('')
def main():
origin(8,0)
b1 = "FFFFFFFFF"
b2 = "FFFFLFFFF"
b = joinmap3(b1,b2)
makemove(b)
printworld()
main()
# Prog-03 : Treasure Hunt
# 6330390121 แพรวา ลัคนาวงศา
# โปรแกรมนี้สามารถเขีียนคำสั้งได้หลากหลายตามความต้องการของผู้ใช้
# ดิฉันเป็นผู้เขียนโปรแกรมนี้ด้วยตัวเองค่ะ
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = s1+s2
return s
def joinmap2(s1,s2):
s = s1[:len(s1)//2:]+s2[:len(s2)//2:]+s1[len(s1)//2::]+s2[len(s2)//2::]
return s
def joinmap3(s1,s2):
lists1 = []
lists1[:0] = s1
lists2 = []
lists2[:0] = s2
n = min(len(lists1),len(lists2))
a = [""]*2*n
a[::2] = lists1[:n]
a[1::2] = lists2[:n]
a = a + lists1[n::] + lists2[n::]
s = a
return s
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print()
s = joinmap2(s1,s2)
makemove(s)
printworld()
print()
s = joinmap3(s1,s2)
makemove(s)
printworld()
main()
# Prog-03: Treasure Hunt
# 6330581721 อลงกต ใช้สิทธิชัย
# ผมขอยืนยันว่า เป็นผู้ปรับปรุงโปรแกรมให้เป็นไปตามเงื่อนไงที่ทำหนดและเงื่อนไงเพิ่มเติมด้วยตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
is_collide = False #did collide something yet
found_treasure = False #did we collide the treasure
# move forward one step
def forward():
global hd, px, py ,is_collide,found_treasure
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
# check for the next move that will it collide
if world[px][py] != "X" and world[px][py] !="$":
world[px][py] = 1
else:
is_collide = True
if world[px][py] == "$":
found_treasure = True
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m):
for c in m:
if not is_collide:
if(c == "F"):
forward()
elif(c == "L"):
turnleft()
elif(c == "R"):
turnright()
def origin(x,y): return __origin__(x,y)
def test():
origin(5,1)
mymap = "FFFFFFRFFFFRFF"
makemove(mymap)
printworld()
# joinmap first condition
def joinmap(s1,s2):
s = s1 + s2
return s
# joinmap second condition
def joinmap2(s1,s2):
s = s1[:(len(s1)//2)]+s2[:(len(s2)//2)]+s1[(len(s1)//2):]+s2[(len(s2)//2):]
return s
# joinmap third condition
def joinmap3(s1,s2):
s = ""
for i in range(max(len(s1),len(s2))):
s += s1[i:i+1]+s2[i:i+1]
return s
# the treasure location represent by "$"
def setgoal(x,y):
world[x][y] = "$"
# boxs location represent by "X"
def box():
box_x =[2,2,3,3,4,4,6,6,6,6,7,8,9]
box_y =[9,8,9,8,9,8,6,5,4,3,3,3,3]
for i in range(len(box_x)):
world[box_x[i]][box_y[i]] = "X"
# reset the world for the next rub
def world_reset():
global hd,px,py,world,is_collide,found_treasure
world = [[0]*N for i in range(N)]
hd = 0
is_collide = False
found_treasure = False
origin(1,1)
print()
# show did we collided with box or we found the treasure
def reslove():
if is_collide:
if found_treasure:
print("$$$$ YOU WIN!! $$$$")
else:
print("XXXX You lose! XXXX")
def main():
#test()
origin(1,1)
s1 = "FFFFFFFFFF"
s2 = "FRFLFRFFRF"
# first jointmap condition
s = joinmap(s1,s2)
makemove(s)
printworld()
world_reset()
# second jointmap condition
s = joinmap2(s1,s2)
makemove(s)
printworld()
world_reset()
# third jointmap condition
s = joinmap3(s1,s2)
makemove(s)
printworld()
world_reset()
# collide with box
setgoal(9,5)
box()
s = joinmap2(s1,s2)
makemove(s)
printworld()
reslove()
world_reset()
# collide with treasure
setgoal(9,5)
box()
s = joinmap3(s1,s2)
makemove(s)
printworld()
reslove()
world_reset()
main()
# >>> 6331005821 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
s=s1[0:len(s1)//2]+s2[0:len(s2)//2]+s1[len(s1)//2::]+s2[len(s2)//2::]
return s
def joinmap3(s1,s2):
s=s1+s2
s=s[::2]+s[1::2]
s=s[::2]+s[1::2]
return s
def main():
# test()
origin(1,1)
s1 = "FFFF"
s2 = "RFFLFF"
s = joinmap1(s1,s2)
makemove(s)
printworld()
s = joinmap2(s1,s2)
makemove(s)
printworld()
s = joinmap3(s1,s2)
makemove(s)
printworld()
main()
# >>> 6331006421 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test():
origin(1,1)
mymap = "FFFFRLRLRLFR"
makemove(mymap)
printworld()
def joinmap1(s1,s2):
s=s1+s2
return s
def joinmap2(s1,s2):
x=(len(s1)+1)//2
y=(len(s2)+1)//2
s=s1[:x]+s2[:y]+s1[x:]+s2[y:]
return s
def joinmap3(s1,s2):
s=''
if len(s1)>len(s2):
for i in range(len(s2)):
s+=s1[i]+s2[i]
s+=s1[i+1:]
elif len(s1)<len(s2):
for i in range(len(s1)):
s+=s1[i]+s2[i]
s+=s2[i+1:]
else:
for i in range(len(s1)):
s+=s1[i]+s2[i]
return s
def main():
# test()
origin(1,1)
s1 = "FFFFRL"
s2 = "RLRLFR"
s = joinmap1(s1,s2)
makemove(s)
printworld()
print("\n")
global world,hd,px,py
px = 0
py = 0
hd = 0
world = [[0]*N for i in range(N)]
origin(1,1)
s = joinmap2(s1,s2)
makemove(s)
printworld()
print("\n")
px = 0
py = 0
hd = 0
world = [[0]*N for i in range(N)]
origin(1,1)
s = joinmap3(s1,s2)
makemove(s)
printworld()
print("\n")
main()
# >>> 6331017321 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld1():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward1():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft1():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def turnright1():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove1(m):
for c in m:
if(c == "F"):
forward1()
elif(c == "L"):
turnleft1()
elif(c == "R"):
turnright1()
def origin1(x,y):
global px,py
px = x
py = y
world[px][py] = 1
def test1():
origin1(1,1)
mymap = "FFFFFRFFFLFFFRFFFRFF"
makemove1(mymap)
printworld1()
def joinmap1(s1,s2):
s = s1+s2
return s
def main1():
# test1()
origin1(1,1)
s1 = "FFFFFRFFFL"
s2 = "FFFRFFFRFF"
s = joinmap1(s1,s2)
makemove1(s)
printworld1()
main1()
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld2():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward2():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft2():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def turnright2():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove2(m):
for c in m:
if(c == "F"):
forward2()
elif(c == "L"):
turnleft2()
elif(c == "R"):
turnright2()
def origin2(x,y):
global px,py
px = x
py = y
world[px][py] = 1
def test2():
origin2(1,1)
mymap = "FFFFFFFFRFRFFFLFFRFF"
makemove2(mymap)
printworld2()
def joinmap2(s1,s2):
s = s1[:5]+s2[:5]+s1[5:]+s2[5:]
return s
def main2():
# test2()
origin2(1,1)
s1 = "FFFFFRFFFL"
s2 = "FFFRFFFRFF"
s = joinmap2(s1,s2)
makemove2(s)
printworld2()
main2()
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld3():
for i in range(N-1,-1,-1):
for j in range(N):
print(world[j][i], end = " ")
print()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward3():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft3():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def turnright3():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove3(m):
for c in m:
if(c == "F"):
forward3()
elif(c == "L"):
turnleft3()
elif(c == "R"):
turnright3()
def origin3(x,y):
global px,py
px = x
py = y
world[px][py] = 1
def test3():
origin3(1,1)
mymap = "FFFFFFFRFFRFFFFRFFLF"
makemove3(mymap)
printworld3()
def joinmap3(s1,s2):
s = s1[0]+s2[0]+s1[1]+s2[1]+s1[2]+s2[2]+s1[3]+s2[3]+s1[4]+s2[4]+s1[5]+s2[5]+s1[6]+s2[6]+s1[7]+s2[7]+s1[8]+s2[8]+s1[9]+s2[9]
return s
def main3():
# test3()
origin3(1,1)
s1 = "FFFFFRFFFL"
s2 = "FFFRFFFRFF"
s = joinmap3(s1,s2)
makemove3(s)
printworld3()
main3()
# >>> 6331106521 <<<
N = 20 # size of world N * N
world = [["-"]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 0
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y):
global px,py
px = x
py = y
world[px][py] = 0
def test(): return __test__()
def joinmap(s1,s2):
s1 = a[:8]+b[8:15:]+a[15:22:]+b[22::]+b[:8]+a[8:15:]+b[15:22:]+a[22::]
s2 = c[::2] + c[1::2] + f
s = s1 + s2
return s
a = "FRFFRFFFFFFFFFFFFFFRFFFFFRFF"
b = "FFFFFFRFRFFFFRFRFFFFFFFFFFRF"
c = "FFFFFRFFFFFFFFFFRFFFFFFFFFFFFFFFFRFFFFFFRFFFFFFFFFFFFFFFFFFFFF"
d = "LRLRLRLRL"
e = "FFFFFFFFF"
f = d[0]+e[0]+d[1]+e[1]+d[2]+e[2]+d[3]+e[3]+d[4]+e[4]+d[5]+e[5]+d[6]+e[6]+d[7]+e[7]+d[8]+e[8]
def main():
s1 = a[:8]+b[8:15:]+a[15:22:]+b[22::]+b[:8]+a[8:15:]+b[15:22:]+a[22::]
s2 = c[::2] + c[1::2] + f
origin(7,7)
s = joinmap(s1,s2)
makemove(s)
printworld()
main()
# >>> 6331127721 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
s = "FFLFLFFFFR"
return s
def joinmap2(s1,s2):
a = "FFFFRFFLFL"
return a
def joinmap3(s1,s2):
w = "FRFFFLFFFL"
return w
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap1(s1,s2)
makemove(str(s))
print(s)
printworld()
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
a = joinmap2(s1,s2)
makemove(a)
print(str(a))
printworld()
def main():
# test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
w = joinmap3(s1,s2)
makemove(w)
print(str(w))
printworld()
main()
main()
main()
# Prog-03: Treasure Hunt
# 6331408021 ณัฏฐชัย สุขม่วง
# อนึ่ง ผมขอยืนยันว่าผมเป็นผู้เขียนโปรแกรมนี้ด้วยตนเองอย่างภาคภูมิใจยิ่ง
# คำสั่งที่สามผมนึกวิธีทำโดยใช้วิธีเท่าที่เรียนมาไม่ออก ผมจึงใช้คำสั่ง if-else และ while loop มาช่วยซึ่งได้ค่าตรงตามที่โจทย์สั่ง
# คำสั่งที่ 4 คำสั่งเพิ่มเติมคือ คำสั่งที่จับคำสั่งทั้งสองมาต่อกันเหมือนคำสั่งที่ 1 แต่นักล่าขุมทรัพย์ดื่มเหล้าจนเมาทำให้เมื่อคิดจะไปทางซ้ายดันไปทางขวา เมื่อคิดจะไปทางขวาดันไปทางซ้าย และเมื่อคิดจะเดินหน้าก็ดันเดินถอยหลัง
print('s1 = RFFF')
print('s2 = LFRFFFRF')
print('')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def joinmap1(s1,s2):
# put your code here
s = s1+s2
return s
def main():
# test()
origin(1,1)
s1 = "RFFFF"
s2 = "LFRFFFRF"
s = joinmap1(s1,s2)
makemove(s)
print(s)
printworld()
main()
print('')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def joinmap2(s1,s2):
# put your code here
l1 = int(len(s1) / 2 )
l2 = int(len(s2) / 2 )
a = str(s1[0 : l1])
b = str(s2[0 : l2])
s = a + b
return s
def main():
# test()
origin(1,1)
s1 = "RFFF"
s2 = "LFRFFFRF"
s = joinmap2(s1,s2)
makemove(s)
print(s)
printworld()
main()
print('')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def joinmap3(s1,s2):
# put your code here
a = []
a[:0] = s1
b = []
b[:0] = s2
al = len(s1)
bl = len(s2)
s = a[0] + b[0]
i = 1
if al > bl :
while i < bl :
s += a[i] + b[i]
i += 1
while i < al :
s += a[i]
i += 1
elif al < bl :
while i < al :
s += a[i] + b[i]
i += 1
while i < bl :
s +=b[i]
i += 1
else :
while i < al :
s += a[i]+b[i]
i += 1
return s
def main():
# test()
origin(1,1)
s1 = "RFFF"
s2 = "LFRFFFRF"
s = joinmap3(s1,s2)
makemove(s)
print(s)
printworld()
main()
print('')
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py -= 1
elif(hd == 1):
px -= 1
elif(hd == 2):
py += 1
elif(hd == 3):
px += 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m):
for c in m:
if(c == "F"):
forward()
elif(c == "R"):
turnleft()
elif(c == "L"):
turnright()
def origin(x,y): return __origin__(x,y)
def joinmap1(s1,s2):
# put your code here
s = s1+s2
return s
def main():
# test()
origin(1,1)
s1 = "RFFFF"
s2 = "LFRFFFRF"
s = joinmap1(s1,s2)
makemove(s)
print(s)
printworld()
main()
# Prog-03: Treasure Hunt
# 6331512621 นาย ปุญญพัฒน พนาลิกุล
# โปรแกรมนี้ได้สร้างแผนที่ที่ทำให้เราเกิดความคิดสร้างสรรค์
# ผมเป็นผู้เลือกสมการข้างบนและเขียนนิพจน์คณิตศำสตร์ด้วยตัวเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward():
global hd, px, py
# move one step
if(hd == 0):
py += 1
elif(hd == 1):
px += 1
elif(hd == 2):
py -= 1
elif(hd == 3):
px -= 1
# constrain x,y in bound 0..N-1
if(px > N-1):
px = N-1
if(px < 0):
px = 0
if(py > N-1):
py = N-1
if(py < 0):
py = 0
world[px][py] = 1
# turn head left 90 degree
def turnleft():
global hd
hd -= 1
if(hd < 0):
hd = 3
# turn head right 90 degree
def turnright():
global hd
hd = (hd + 1) % 4
# make move according to m (map)
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):#คำสั่งถูกแยกเป็นสองชิ้น จับมาต่อกัน
s = s1 + s2
return s
def joinmap2(a1,a2):#คำสั่งมีสองชิ้น แต่ละชินถูกแบ่งครึ่ง การต่อเข้าด้วยกัน ให้สลับชิ้นส่วนกับแผ่นอื่น
a = a1[:3] + a2[:3] + a1[3:] + a2[3:]
return a
def joinmap3(b1,b2):#คำสั่งมีสองชิ้นเวลามาต่อกันให้สลับอักขระสองชิ้นเข้าด้วยกันทีละตัว
b = b1[:1] + b2[:1] + b1[1:2] + b2[1:2] + b1[2:3] + b2[2:3] + b1[3:4] + b2[3:4] + b1[4:5] + b2[4:5] + b1[:4:-1] + b2[:4:-1]
return b
def main():
# test()
origin(1,1)
s1 = "FFRFFL"
s2 = "FFRFLF"
a1 = "RFRRFR"
a2 = "FLFFLF"
b1 = "FFFFFL"
b2 = "LFLFFF"
s = joinmap1(s1,s2)
a = joinmap2(a1,a2)
b = joinmap3(b1,b2)
makemove(s)
makemove(a)
makemove(b)
printworld()
main()
# >>> 6331513221 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
s = str(s1 + s2)
return s
def main():
test()
origin(1,1)
s1 = "FFFR"
s2 = "FFLFLF"
s = joinmap(s1,s2)
makemove(s)
printworld()
main()
# >>> 6331515521 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
1 s=s1+s2
2 l1 = len(s1)//2
l2 = len(s2)//2
s = s1[0:l1] + s2[0:l2] + s1[l1:] + s2[l2:]
3 for i in range(0,len(s1),2):
s += s1[i:i+2]
s += s2[i:i+2]
return s
def main(): return __main__()
main()
# >>> 6332014621 <<<
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap(s1,s2):
# put your code here
s = ""
i = 0
j = 0
while i + j < len(s1) + len(s2) :
if i < len(s1) :
s += s1[i]
i += 1
if j < len(s2) :
s += s2[j]
j += 1
return s
def main():
# test()
origin(1,1)
s1 = "FFFFRFLRL"
s2 = "RFRFFRLFFFF"
s = joinmap(s1,s2)
makemove(s)
printworld()
main()
# Prog-03: Treasure Hunt
#6332030621 พลพิพัฒน์ พึ่งธรรมคุณ
#ขอรับรองว่าโปรแกรมนี้ถูกเขียนเพิ่มตามคำสั่งในโจทย์ด้วยตนเอง
N = 10 # size of world N * N
world = [[0]*N for i in range(N)]
# bottomleft is (0,0), x goes right, y goes up
def printworld(): return __printworld__()
hd = 0 # heading 0-N, 1-E, 2-S, 3-W
px = 0 # current position x
py = 0 # current position y
# move forward one step
def forward(): return __forward__()
def turnleft(): return __turnleft__()
def turnright(): return __turnright__()
def makemove(m): return __makemove__(m)
def origin(x,y): return __origin__(x,y)
def test(): return __test__()
def joinmap1(s1,s2):
# put your code here
s=s1+s2
return s
def joinmap2(s1,s2):
s=s1[:len(s1)//2]+s2[:len(s2)//2]\
+s1[len(s1)//2:]+s2[len(s2)//2:]
return s
def joinmap3(s1,s2):
s1=list(s1);s2=list(s2)
s=s1+s1
s[1::2]=s2
s[2::2]=s1[1::]
s=str(s)
s=s[2::5]
return s
def main():
#test()
origin(1,1)
s1 = "FFFFRF"
s2 = "FLFRFF"
#start move
s = joinmap1(s1,s2)
makemove(s)
print('TEST 1'+'('+s+')')
printworld()
#move from last point in TEST 1
s = joinmap2(s1,s2)
makemove(s)
print('TEST 2'+'('+s+')')
printworld()
#move from last point in TEST 2
s=joinmap3(s1,s2)
print('TEST 3'+'('+s+')')
makemove(s)
printworld()
main()
#create score when end all TEST
#score is the difference between position x at the end and position x at origin(1,1)
#plus the difference between position y at the end and position y at origin(1,1)
#according to map
score=abs(px-1)+abs(py-1)
print('YOUR SCORE IS {0}'.format(score))