Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

python random module - seed number - generate map - recreate map

import random

---------------------------------------------------------------------------------------------

(1) Example:

THREE RANDOM LETTERS

def new_tag_letters():

    LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

    tag_letter_1 = random.choice(LETTERS)

    tag_letter_2 = random.choice(LETTERS)

    tag_letter_3 = random.choice(LETTERS)

    return tag_letter_1, tag_letter_2, tag_letter_3

---------------------------------------------------------------------------------------------

(2)  Example:

PREPARE A RANDOM NUMBER FOR SEED

random_number  = random.random()                   

0.7152380063066679                                                     # decimal number

 random_number = round(random_number,4)

0.7152                                                                                         #round decimal number to four digits

 random_number = random_number * 10000

7152                                                                                             #make into integer

---------------------------------------------------------------------------------------------

NUMBERS ARE LINKED TO UNIQUE SEED VALUES, SHARING THE SAME FORMAT

random.seed(7152       #Load number first. The next random output is the seed value.

seed_output = random.random()

0.8921694109464761     <--  FACTOR USED TO CONSTRUCT MAP WITH

---------------------------------------------------------------------------------------------

4X4 SIMPLE MAP

[ 8, 9, 2, 1]

[ 6, 9, 4, 1]

[ 0, 9, 4, 6]

[ 4, 7, 6, 1]

---------------------------------------------------------------------------------------------

map.add(BlockType_8(seed_output))

map.add(BlockType_9(seed_output))

map.add(BlockType_2(seed_output))

map.add(BlockType_1(seed_output))

---------------------------------------------------------------------------------------------

BlockType_1 : Healing Area

seed_output = 0.8921694109464761

result_1 = round(seed_output * 10) + self.row_number + self.column_number 

result_2 = round(seed_output * 100) + self.row_number + self.column_number

result_3 = round(seed_output * 1000) + self.row_number + self.column_number

if result_1 % 2 == 0 and result_2 % 2 == 0 :                  #even number check

    map_items.add(FirstAidKit())

if (result_1 + result_2 + result_3)  % 30  == 0:           #divisible by 30, remainder is 0

    map_items.add(ExtraLife())

---------------------------------------------------------------------------------------------

ADDITIONAL MAP BLOCKS   (100 different block types in game)

0.8921694109464761      

[89, 21, 69, 41, 09, 46,  47, 61]

[08, 92, 16, 94, 10, 94, 64, 76, 1]    

---------------------------------------------------------------------------------------------

number_string = str(0.8921694109464761)

number_string = number_string.replace("." , "")

"08921694109464761"

--------------------------------------------------------------------------------------------

WIDER RANGE OF BLOCKS

[892,169,410,946,476,1]      <-- rarer blocks with items

[089,216,941,094,647,61]     

---------------------------------------------------------------------------------------------

SPLIT STRING EVERY SECOND CHARACTER

decimal_number = round(seed_output, 16)   #round off to 16 to avoid 17 outputs.

decimal_string = str(decimal_number)

integer_string = decimal_string.replace("0." , "")

s = integer_string

n = 2

two_digit_form = [s[i:i+n] for i in range(0, len(s), n)]   #searched solution - returns array

block_type_number = int(two_digit_form[0])

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.