Site hosted by Angelfire.com: Build your free website today!


โปรแกรมแสดงการเคลื่อนที่ด้วยวิธีสุ่ม รอบ ๆ cell ที่กำลังพิจารณา


จากคำถามของคุณ icyZ ครับ

คือนี่เป็น algo สร้าง map โดยใช้ 2-dimensional array
แต่เท่าที่อ่าน algorithm งงตรงคำว่า move into that cell
ช่วยหน่อยนะครับพี่ๆ แล้วไอ้ที่บอกให้ look in random order นี่ทำไงนึกไม่ออกจริงๆ
สุดท้ายการ mark ว่า visit แล้วนี่ทำไงครับ?

> for x = 1 to ncols
> for y = 1 to nrows
> done = false
> do while not done
> look at the adjacent four cells in random order
> if the cell under consideration still has all four walls intact
> break down that wall
> move into that cell
> else
> if you have visited all four adjacent cells
> done = true
> end if
> end if
> loop
> next y
> next x

ตัวอย่างของ program ก่อนที่จะรัน (ก่อนกดปุ่ม Take a look)

ตัวอย่างของ program หลังกดปุ่ม Take a look แล้ว ตัวเลขในแต่ละเซลล์แสดงลำดับการเข้าเยี่ยมแต่ ละห้อง ซึ่งตัวเลขได้จากการสุ่มโดยใช้ฟังก์ชั่น randbetween ใน EXCEL ครับ ในการสุ่มบางครั้งจะได้ ตัวเลือกเป็นห้องที่เคยเปิดเข้าไปก่อนแล้วดังนั้น จึงต้องเลือกใหม่ (ดังจะสังเกตได้จากลำดับตัวเลข ถึง แม้จะเป็นจากน้อยไปหามาก แต่ก็ไม่ต่อเนื่องกัน)

ตัวอย่างของ algorithm ใน VBA6.0 สำหรับ EXCEL2000 ครับ


หากมีข้อแนะนำกรุณาติดต่อที่อีเมลล์ : Practical_x_2@hotmail.com