import curses
import time
import re
from lib import *

#################################################
################## title #######################
#################################################

def backBtn(stdscr,clicks):
    btn = [
        "┏━━━━━━┓",
        "┃<<back┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,1,1,btn):
        return True
    return False

def GazBtn(stdscr,clicks,y,x):
    gazBtn = [
        "┏━━━━━━━━━━━━━┓",
        "┃             ┃",
        "┃    Start    ┃",
        "┃             ┃",
        "┗━━━━━━━━━━━━━┛",
        ]
    if button(stdscr,clicks,y,x,gazBtn):
        return True
    return False

def Gaz(stdscr,ctx):
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # Alligatorn2 font
    prnt(stdscr,0,0,"""

  .:::::|                       
  `:::::>:::\ .::\ .::/ :~~/    
  ,::::/ :::/ `::| `::\ :::,    
         :|                     
::::::|            :|           
  ::|  :::| .::\ :':| :~~/ :::| 
  ::|  :|   `::| :::| :::, :|   
                                

       ::::::::  :::::::::     :::      ::::::::  ::::::::::        
      :+:    :+: :+:    :+:  :+: :+:   :+:    :+: :+:               
      +:+        +:+    +:+ +:+   +:+  +:+        +:+               
      +#++:++#++ +#++:++#+ +#++:++#++: +#+        +#++:++#          
             +#+ +#+       +#+     +#+ +#+        +#+               
      #+#    #+# #+#       #+#     #+# #+#    #+# #+#               
       ########  ###       ###     ###  ########  ##########        
::::::::::: :::::::::      :::     :::::::::  :::::::::: :::::::::  
    :+:     :+:    :+:   :+: :+:   :+:    :+: :+:        :+:    :+: 
    +:+     +:+    +:+  +:+   +:+  +:+    +:+ +:+        +:+    +:+ 
    +#+     +#++:++#:  +#++:++#++: +#+    +:+ +#++:++#   +#++:++#:  
    +#+     +#+    +#+ +#+     +#+ +#+    +#+ +#+        +#+    +#+ 
    #+#     #+#    #+# #+#     #+# #+#    #+# #+#        #+#    #+# 
    ###     ###    ### ###     ### #########  ########## ###    ### 

                                                                                      
               ______       _____          ____         _____        ______           
           ___|\     \  ___|\    \    ____|\   \    ___|\    \   ___|\     \          
          |    |\     \|    |\    \  /    /\    \  /    /\    \ |     \     \         
          |    |/____/||    | |    ||    |  |    ||    |  |    ||     ,_____/|        
       ___|    \|   | ||    |/____/||    |__|    ||    |  |____||     \--'\_|/        
      |    \    \___|/ |    ||    |||    .--.    ||    |   ____ |     /___/|          
      |    |\     \    |    ||____|/|    |  |    ||    |  |    ||     \____|\         
      |\ ___\|_____|   |____|       |____|  |____||\ ___\/    /||____ '     /|        
      | |    |     |   |    |       |    |  |    || |   /____/ ||    /_____/ |        
       \|____|_____|   |____|       |____|  |____| \|___|    | /|____|     | /        
          \(    )/       \(           \(      )/     \( |____|/   \( |_____|/         
           '    '         '            '      '       '   )/       '    )/            
                                                          '             '             
                                                                                      
 _________________      _____          ____        _____        ______        _____   
/                 \ ___|\    \    ____|\   \   ___|\    \   ___|\     \   ___|\    \  
\______     ______/|    |\    \  /    /\    \ |    |\    \ |     \     \ |    |\    \ 
   \( /    /  )/   |    | |    ||    |  |    ||    | |    ||     ,_____/||    | |    |
    ' |   |   '    |    |/____/ |    |__|    ||    | |    ||     \--'\_|/|    |/____/ 
      |   |        |    |\    \ |    .--.    ||    | |    ||     /___/|  |    |\    \ 
     /   //        |    | |    ||    |  |    ||    | |    ||     \____|\ |    | |    |
    /___//         |____| |____||____|  |____||____|/____/||____ '     /||____| |____|
   |`   |          |    | |    ||    |  |    ||    /    | ||    /_____/ ||    | |    |
   |____|          |____| |____||____|  |____||____|____|/ |____|     | /|____| |____|
     \(              \(     )/    \(      )/    \(    )/     \( |_____|/   \(     )/  
      '               '     '      '      '      '    '       '    )/       '     '   
                                                                   '                  
    """)
    stdscr.refresh()

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,73)
        if exited:
            return None

        if introBtn(stdscr,clicks,6,68):
            return Intro

        if GazBtn(stdscr,clicks,11,66):
            return StarMap

        if tradeBtn(stdscr,clicks):
            return PlanetTrade

        stdscr.refresh()
        start = wait(start)
    return StarMap

"""

i. 

TRADERS-... and constantly in advance of the political hegemony of the Foundation were the 
Traders, reaching out tenuous fingerholds through the tremendous distances of the Periphery. 
Months or years might pass between landings on Terminus; their ships were often nothing 
more than patchquilts of home-made repairs and improvisations; their honesty was none of the 
highest; their daring... 

Through it all they forged an empire more enduring than the pseudo-religious despotism of the 
Four Kingdoms... 


Tales without end are told of these massive, lonely figures who bore half-seriously, 
half-mockingly a motto adopted from one of Salvor Hardin's epigrams, "Never let your sense of 




morals prevent you from doing what is right!" It is difficult now to tell which tales are real and 
which apocryphal. There are none probably that have not suffered some exaggeration.... 

ENCYCLOPEDIA GALACTICA 


TRADERS-... With psychohistoric inevitability, economic control of the Foundation grew. The 
traders grew rich; and with riches came power.... 

It is sometimes forgotten that Hober Mallow began life as an ordinary trader. It is never 
forgotten that he ended it as the first of the Merchant Princes.... 


ENCYCLOPEDIA GALACTICA 
"""

#################################################
############### Harry Seldon  ###################
#################################################

def Intro(stdscr,ctx):
    scene = """

'This marks the Fall of the Galactic Empire.'

From now on, and into the centuries, 
the path you must take is inevitable. 

To reduce it to its fundamentals, it is this: 

    You are a planet suddenly cut off from 
    the still-civilized centers of the Galaxy, 
    and threatened by your stronger neighbors. 

    You are a small world of scientists 
    surrounded by vast and rapidly expanding 
    reaches of barbarism. 

    You are an island of nuclear power 
    in a growing ocean of more primitive energy; 
    but are helpless despite that, 

    because of your lack of metals.

that is, the solution to your dilemma – is, of course, obvious!"


  ___________________   _______  __________ __________          
 /_________/    _o___) /   O   \/   /_____//   /_____/          
 `%%%%%%%%%/___|%%%%%'/___/%\___\___\%%%%%'\___\%%%%%'          
 `BBBBBBBB' `B'       `BB'   `BB'`BBBBBBBB' `BBBBBBBB'          
 _________  _________   _______  _________ __________ _________ 
/__     __\|    _o___) /   O   \|     O   Y   /_____/|    _o___)
`%%|___|%%'|___|\____\/___/%\___\_________|___\%%%%%'|___|\____\
    `B'     `BB' `BBB'`BB'   `BB'`BBBBBBB' `BBBBBBBB' `BB' `BBB'

    """
    keys = getCh(stdscr)
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys = getCh(stdscr)

        if anykey(stdscr,keys):    return Gaz

        stdscr.refresh()
        start = wait(start)
    return None

def introBtn(stdscr,clicks,y,x):
    btn = [
        "┏━━━━━━━━━━━┓",
        "┃           ┃",
        "┃   intro   ┃",
        "┃           ┃",
        "┗━━━━━━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

#################################################
################## trade  #######################
#################################################

def findChar(scene,char,nth=0):
    y = 0
    n = 0
    for l in scene.split('\n'):
        x = 0
        for c in l:
            if c == char:
                if n >= nth:
                    return y,x
                n += 1
            x += 1
        y += 1
    return None,None

def countChar(scene,char):
    n = 0
    for l in scene.split('\n'):
        for c in l:
            if c == char:
                n += 1
    return n


def dealBtn(stdscr,clicks,scene):
    btn = [
        "┏━━━━━━━━━━━━━━━┓",
        "┃      Deal     ┃",
        "┗━━━━━━━━━━━━━━━┛",
            ]
    y,x = findChar(scene,'?',0)
    if not y:
        return False
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def balanceBtn(stdscr,clicks,scene,cash):
    cashStr = str(cash)[:10].ljust(11)
    btn = [
        "┏━━━━━━━━━━━━━━━┓",
        "┃ $"+cashStr+"  ┃",
        "┗━━━━━━━━━━━━━━━┛",
            ]
    y,x = findChar(scene,'$',0)
    if not y:
        return False
    if button(stdscr,clicks,y,x,btn):
        return True
    return False


def placeProductsOnWithPriceTag(stdscr,clicks,scene,char,buttons,prices):
    n=0
    for loadBtn in buttons:
        y,x = findChar(scene,char,n)
        if y:
            if loadBtn in prices:
                if loadBtn(stdscr,clicks,y,x):
                    return loadBtn  
                price = prices[loadBtn]
                cashStr = str(price)[:6].ljust(6,'━')
                prnt(stdscr,y,x,'$'+cashStr+'┓')
            else:
                prnt(stdscr,y,x,'nope')
                loadBtn(stdscr,clicks,y+1,x)
            n += 1
    return None

def placeProductsOn(stdscr,clicks,scene,char,buttons):
    n=0
    for loadBtn in buttons:
        y,x = findChar(scene,char,n)
        if y:
            if loadBtn(stdscr,clicks,y,x):
                return loadBtn  
            n += 1
    return None

def PlanetTrade(stdscr,ctx):
    scene = """
                                                      ━┏┛┏━┃┏━┃┏━ ┏━┛
                                                       ┃ ┏┏┛┏━┃┃ ┃┏━┛
                                                       ┛ ┛ ┛┛ ┛━━ ━━┛
┏━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  ┏━┛┏━┃┏━┃┏━┛┏━┃ ┃┃  ┏┏ ┏━┃┏━┃┃ ┃┏━┛━┏┛                ?                  ┃
┃  ┃  ┏━┃┏┏┛┃ ┃┃ ┃ ┃┃  ┃┃┃┏━┃┏┏┛┏┛ ┏━┛ ┃                                    ┃
┃  ━━┛┛ ┛┛ ┛━━┛━━┛ ┃┃  ┛┛┛┛ ┛┛ ┛┛ ┛━━┛ ┛                                    ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ $                ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┗━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    """
    scenePurified = re.sub(r"[+|\-|?|=|$]", ' ', scene)

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # this part from sqlite/context
    cargo = [NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,] # space ship
    cargoMax = countChar(scene,'+')

    wallet = 0  # player cash
    market = [] + ([FissibleMaterial,]*10) + ([Metal,] * 20)
    prices = {
            NuclearTechnology: 1000,
            BiologicalTechnology: 100,
            MedicalTechnology: 300,
            IndustrialTechnology: 500,
            ReligiousTechnology: 1000,
            ForceField: 5000,
            LuxuryTechnology: 100,
            FissibleMaterial:50,
            Metal:10,
            PreciousMetal:100,
            RareMetal:500,
            }

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)
        prnt(stdscr,0,0,scenePurified)

        if backBtn(stdscr,clicks):      return StarMap
        if starmapBtn(stdscr,clicks):   return StarMap

        sell = placeProductsOnWithPriceTag(stdscr,clicks,scene,'+',cargo,prices)
        if sell in prices:
            market.append(sell)
            cargo.remove(sell)
            wallet += prices[sell]

        buy = placeProductsOnWithPriceTag(stdscr,clicks,scene,'-',market,prices)
        if buy in prices and len(cargo) < cargoMax:
            cargo.append(buy)
            market.remove(buy)
            wallet -= prices[buy]

        if balanceBtn(stdscr,clicks,scene,wallet):
            pass

        if wallet >= 0:
            if dealBtn(stdscr,clicks,scene):
                return StarMap

        stdscr.refresh()
        start = wait(start)
    return None

def tradeBtn(stdscr,clicks):
    btn = [
        "┏━━━━━┓",
        "┃trade┃",
        "┗━━━━━┛",
            ]
    if button(stdscr,clicks,1,22,btn):
        return True
    return False


# ________ NUCLEAR TECHNOLOGY ________
NuclearTechnologyKey = "Nuclear Technology"

def NuclearTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃Nuclear",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Miniaturized_Nuclear_Power_Units(stdscr,ctx):
    scene = """
        "┃Miniaturized Nuclear Power Units┃",
Small, durable atomic generators 
used for cities, factories, and 
castles. Far smaller and more 
reliable than decaying imperial 
reactors. Often disguised as 
sacred relics. These devices give 
the Foundation decisive leverage 
over kingdoms that cannot repair 
or reproduce them.
    """

def Domestic_Power_Devices(stdscr,ctx):
    scene = """
        "┃Domestic Power Devices ┃",
Household-scale nuclear 
appliances providing 
lighting, heating, and 
mechanical power. Sold as 
luxury items to local 
elites. Their reliability 
contrasts sharply with 
pre-atomic infrastructure. 
Dependency on Foundation 
technicians ensures long-term 
political influence through 
maintenance and “religious” 
servicing.
    """

# ________ AGRICULTURAL TECHNOLOGY ________
BiologicalTechnologyKey = "Agricultural Technology"
def BiologicalTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃  bio ┃",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Agricultural_Equipment(stdscr,ctx):
    scene = """
        "┃Agricultural Equipment┃",
Atomic-powered farming tools and soil 
processors. Dramatically increase crop 
yields on marginal worlds. Often 
introduced selectively to bind agrarian 
planets economically. These tools reduce 
famine risk while making local economies 
structurally dependent on Foundation 
supply chains.
    """

# ________ MEDICAL TECHNOLOGY ________
MedicalTechnologyKey = "Medical Technology"
def MedicalTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃Medical",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Medical_Technology(stdscr,ctx):
    scene = """
        "┃Medical Technology┃",
Advanced medicines diagnostic 
tools and life-extending treatments. 
Far superior to post-Imperial medical 
knowledge. Frequently restricted to 
ruling classes. Health becomes a 
political bargaining chip reinforcing 
loyalty while preventing technological 
diffusion beyond approved intermediaries.
    """



# ________ INDUSTRIAL TECHNOLOGY ________
IndustrialTechnologyKey = "Industrial Technology"
def IndustrialTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "Industry",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Industrial_Machinery(stdscr,ctx):
    scene = """
        "┃Industrial Machinery┃",
Compact high-efficiency 
manufacturing devices powered 
by nuclear cells. Enable small 
planets to maintain industry 
without large infrastructure. 
Traders control spare parts 
and technical knowledge ensuring 
that industrial growth remains 
aligned with Foundation interests.
    """

# ________ RELIGIOUS TECHNOLOGY ________
ReligiousTechnologyKey = "Religious Technology"
def ReligiousTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "Religiou",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Religious_Artifacts(stdscr,ctx):
    scene = """
        "┃Religious Artifacts┃",
Technological devices presented 
as sacred instruments: power 
controllers diagnostic tools 
protective fields. Integrated 
into the Church of Science. 
Their operation is ritualized 
preventing local understanding 
while maintaining the illusion 
of divine authority tied to 
Foundation priests.
    """


# ________ FORCE FIELD ________
ForceFieldKey = "Force Field"
def ForceField(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃Force ┃",
        "┃ Field┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Protective_and_Control_Devices(stdscr,ctx):
    scene = """
        "┃Protective and Control Devices┃",
Force-field generators, radiation 
shields and security systems. Used 
to protect rulers and strategic 
locations. These devices reinforce 
the perceived invincibility of 
Foundation-backed regimes and 
discourage rebellion through 
technological intimidation rather 
than open warfare.
    """

# ________ LUXURY TECHNOLOGY ________
LuxuryTechnologyKey = "Luxury Technology"
def LuxuryTechnology(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃Luxury┃",
        "┃ Tech ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

def Luxury_Goods(stdscr,ctx):
    scene = """
        "┃Luxury Goods┃",
High-quality manufactured 
items: lighting systems 
precision instruments and 
refined materials. Serve no 
strategic purpose directly 
but function as status 
symbols. Luxury trade smooths 
diplomatic relations and opens 
doors for deeper technological 
and political penetration.
    """

# ____________ ECONOMIC CONTRACTS AND TRADE MONOPOLIES ____________
def Technical_Expertise(stdscr,ctx):
    scene = """
        "┃Technical Expertise┃",
Arguably the most important 
export. Traders sell access 
to Foundation engineers and 
priests not knowledge itself. 
Expertise is deliberately 
compartmentalized ensuring 
locals can operate devices 
but never understand them 
preserving asymmetrical 
power indefinitely.
    """

def Economic_Contracts_and_Trade_Monopolies(stdscr,ctx):
    scene = """
        "┃Economic Contracts & Trade Monopolies┃",
Not physical goods but binding 
agreements tying planetary 
economies to Foundation supply 
lines. Traders act as negotiators 
and enforcers. These contracts 
replace military conquest with 
economic subjugation marking the 
transition to mercantile imperialism.
    """

# ________ FISSIBLE MATERIAL ________
FissibleMaterialKey = "Fissible Material"
def FissibleMaterial(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "Fissible",
        "Material",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False


MetalKey = "Metal"
def Metal(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "┃ Metal┃",
        "┃      ┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False


PreciousMetalKey = "Precious Metal"
def PreciousMetal(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "Precious",
        "┃ Metal┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

RareMetalKey = "Rare Metal"
def RareMetal(stdscr,clicks,y,x):
    # ___123456789
    btn = [
        "┏━━━━━━┓",
        "Rare",
        "┃ Metal┃",
        "┗━━━━━━┛",
            ]
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

#################################################
############### Star's map ######################
#################################################

def locate(scene, name, nth=0):
    y = 0
    for l in scene.split('\n'):
        try:
            x = l.index(name)
            if x > 0:
                return y,x
        except:
            pass
        finally:
            y += 1
    return None,None

def locateBtn(stdscr,clicks,scene ,name):
    planet_y,planet_x = locate(scene ,name)
    if planet_y and PlanetBtn(stdscr,clicks,planet_y,planet_x,name):
        return True
    return False

galaxyBg = """
┏━┛━┏┛┏━┃┏━┃┏━┛  ┏┏ ┏━┃┏━┃      .... .....                                       
━━┃ ┃ ┏━┃┏┏┛━━┃  ┃┃┃┏━┃┏━┛:-+*##+*++==+***+*-::..                                
━━┛ ┛ ┛ ┛┛ ┛━━┛  ┛┛┛┛ ┛┛  ==:=++====+=======+*++*=:.                             
               .::=++==-=+---::::::::::-----====*%*++=                           
            .::-::----::::.....      ......::---=+**##+:                         
          .-++-::::......         .        ....::-=+**=++-:.                     
        ::::.......                            .::::-==+%%#=:.                   
      ::==:..                  . .             . ....:-=+*%#%=:                  
    .-::...                    .::::.:::--......   ...:-=*#@@@+-.                
   .::...                    .:--=+=++++##***+=-:.......-++#@@*=:.               
  :+-.                     ....:::-----===+++**#*+-..:..:--+*##*+-:              
  ::.                 .....::-===+***##++**+=+==+*+---=:.:-=+#%%*+-.             
                   .=+==--=++#%@@@@@@@@@@@@@@%*+++===+=-:.:-=+*##*+-.            
..              .:--:::-=+*#@@@@@@@@%#*#%%@@@@@@@%*+**#*:.::-=*%%#*=.            
              .--+:.::-=*%%@@@%#*=---:::--=+*%@@@@@@%***=:..:-+*###+:.           
             .:--:..-=*#%@@@#+=--.::---:::-==*%@@@@@@%*+*#:.:-=+#%#*-.           
              .+=::-=*@@@@%+-::::.     ..-+*%@@@@@@@@@%+*+:::-=+*#%#=:           
              .::.-+#@@@#+=-::=-     .=###%@@@@@@@@@@@@+-:::::-+*%@#+:   ...     
             .:.::+%@@@%*=--=+.    .=+*%@@@@@@@@@@@@@+. .--..:=+#%%*=:   .-:     
           .-=:.:-+@@@@*=--=-     -*##@@@@@@@@@@@%**#:  :=-:.:=*%@%#+.  .:.      
           --. .:+#@@@#+--=-.    -+*#@@@@@@@@@@@@*+%+   .....:=#%@@@-. .....     
          ..   .:+%@@%*=-==:    :#+#@@@@@@@@@@@@%*+-   .....:-+%@%@+.    ..      
           .   .:+@@##+--=-.   :%*#@@@@@@@@@@@@@%+:   ::  .:-+#@@@*-.   :-:      
           ..  .=%@@@#+--+=.   +@#@@@@@@@@@@@@*#=.  :==. ..-+#%@@#=:   .-.       
          .:   .-+@@@#+=---:..=@@@@@@@@@@@@@%*-:.....   .:-+#@@@%+:. .-=         
          :..   :+%@@%+====-+%@@@@@@@@@@@#+-::..:--    ::-+%@@@%+-.  ..          
                .=%@@%*+=-=##%@@@@@@@@%#+=-----:... .:-==#@@@%#+-.               
                 -%@@%#*===%@@%@@@@@@#*===--:::..::-=*#%@@@@@#+-.    ...         
                 :%@@@#*++=+@%##%@@@@@@%#***+++++*#*%%@@@@@%*-:.. ..:..          
                  -*@@%#*+===***###%%@@@@@@@@@@@@@@@@@%%*+=-:...:==-.            
                  .:+@@%#*+==+===+*#%##**###@@@@@####*+==-----+%+=::.            
              .    .-*%@%##+==-:-=+++#%%%#*++++++++==--:::::.::..              . 
              .     .-#%%@@*++--:-=*+===+===++****+**+=-:..             :....... 
               .      -+#@@%**+=-::-+*=--:::::-==--::::..            ...::-+*=.  
               .       :+###%%#*+=-----=+#*-:....               ...:::--=-=--.   
                 .      .:-=#@%##*++==--=++=-=+=::.....  ......::::---=++=:.     
                         .:-+%%#%#%@##*+====--+==--==---::::::---==*%%%=:.       
                          ..-==-+*#%@@%#*+**+*++**===-==-=========+#%-:          
                              ...:-=*******####%%%@@*++**##%#*#+==-:.            
                                   .:-----=+**#%*+*##+==-=+==:..                 
                              .           ....::--:::::...                       
                              =                                                  
                                                                                 
                                                                                 
"""

def StarMap(stdscr,ctx):
    scene = """
┏━┛━┏┛┏━┃┏━┃┏━┛  ┏┏ ┏━┃┏━┃                                                        +
━━┃ ┃ ┏━┃┏┏┛━━┃  ┃┃┃┏━┃┏━┛                                                        +
━━┛ ┛ ┛ ┛┛ ┛━━┛  ┛┛┛┛ ┛┛                                                          +
                                                                    earth         +
-                                          solaria                                +
                                                                                  - 
 terminus                                                                         + 
              anacreon                                       

               thespis
                                                 aurora             + 
     smyrno                                                                       - 
-                                                                                 +
                         helicon                                                     - 
                                                                             + 
                                     trantor                                      + 
                                                                                  + 
-                     korell                                               +
                                                               tazenda            + 
                                                                                  + 
-                                                                                 +
                                            rossem                                - 
                                                                   starend      + 
-   |     |     |     |     |     |     |     |     |     |     |     |     |     |
    """
    #""".replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()


    prnt(stdscr,3,0,galaxyBg)

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        #if backBtn(stdscr,clicks):
        #    return Planet 
        #planet_y, planet_x = locate(scene ,"planet")
        #if PlanetBtn(stdscr,clicks,planet_y,planet_x):
        #    return Planet 
        if tradeBtn(stdscr,clicks):
            return PlanetTrade

        if locateBtn(stdscr,clicks,scene ,"terminus"):   return Terminus
        if locateBtn(stdscr,clicks,scene ,"anacreon"):   return Anacreon
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"smyrbo"):     return Smyrno
        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon
        if locateBtn(stdscr,clicks,scene ,"korell"):     return Korell
        if locateBtn(stdscr,clicks,scene ,"rossem"):     return Rossen 
        if locateBtn(stdscr,clicks,scene ,"aurora"):     return Aurora 
        if locateBtn(stdscr,clicks,scene ,"earth"):      return Earth
        if locateBtn(stdscr,clicks,scene ,"solaria"):    return Solaria
        if locateBtn(stdscr,clicks,scene ,"starend"):    return StarEnd
        if locateBtn(stdscr,clicks,scene ,"tazenda"):    return Tazenda
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

def starmapBtn(stdscr,clicks):
    btn = [
        "┏━━━━━━━━━┓",
        "┃Stars Map┃",
        "┗━━━━━━━━━┛",
            ]
    if button(stdscr,clicks,1,10,btn):
        return True
    return False

def PlanetBtn(stdscr,clicks,y,x,name):
    spc = '━' * len(name)
    gazBtn = [
        "x ┏"+spc+"┓",
        " \\┃"+name+"┃",
        "  ┗"+spc+"┛",
        ]
    if button(stdscr,clicks,y+3,x,gazBtn):
        return True
    return False

#################################################
################## planet #######################
#################################################

# ascii art generator, use "emboss"

"""

Arcadia 

DARELL, ARKADY novelist, born 1 1, 5, 362 F.E., died 1, 7, 443 F.E. Although primarily a writer 
of fiction, Arkady Darell is best known for her biography of her grandmother, Bayta Darell. 

Based on first-hand information, it has for centuries served as a primary source of information 
concerning the Mule and his times. ... Like "Unkeyed Memories", her novel "Time and Time and 
Over" is a stirring reflection of the brilliant Kalganian society of the early Interregnum, based, it 
is said, on a visit to Kalgan in her youth.... 

ENCYCLOPEDIA GALACTICA 
"""

# _______________TERMINUS_______________________


def Terminus(stdscr,ctx):
    scene = """
━┏┛┏━┛┏━┃┏┏ ┛┏━ ┃ ┃┏━┛                                                                         ..............
 ┃ ┏━┛┏┏┛┃┃┃┃┃ ┃┃ ┃━━┃                                                         .:--::::-----------=*#************+++++====-.
 ┛ ━━┛┛ ┛┛┛┛┛┛ ┛━━┛━━┛                                                ..:-+++++----------==========--::=+++========++**#*****+++=:.
Its location (see map) was                                    .:==+++**##+================++++++======-:*#%%%%%%%%%%%#+--=*##***++==:
an odd one for the role it                               :-=+++**+===++====+++++++++++++++++++++++++++==-:=*#####%%%%%%%%%%*+-=+##**+++-.
was called upon to play in                          .:+=++***=-=%%%%%+=+++++++++++++++++++++++++*****++++=-.:-=++***###%%%%%%%%%-:=##**+++:
Galactic history, and yet                       .-=++***=-+#%%%%%##*=+++***+++++++++++++++**********++++++==:...:::--+***##%%%%%%%#--*#**+++:
as many writers have never                   .-+++**+-=#%%%%%###**+=+++*********************************+++==:  ....:::-+***##%%%%%%#--##*+++-
tired of pointing out, an                  ==++*#=:*%%%%%%##*++-.:=++************************************++++=:    ....:.:-***#%%%%%%%-:##*+++=
inevitable one.                         -=++**+:+%%%%%%##*+=::...=++**************************************+++=-.     ....:.-+**###%%%%%:-%**+=+.
                                      -=++*#=:*%%%%%##**+:::... -++****************************************++==-      ....::-***##%%%%%=:##*+=+.
Located on the very fringe          :=++*#+:*%%%%%##**=:::...  .=++**************************************++++++-.      ...:.:***##%%%%%--%**+=+.
of the Galactic spiral, an         =+++*#--%%%%%##**+-::...    :=++************************************+++++*++-.     ...:::=**##%%%%%*:+#*+++:
only planet of an isolated        ==++**:=%%%%%%#**+:::...     :+=++*********************###********++++*##**+=-.    ....::-+*##%%%%%*:+#*++=:
sun, poor in resources and       =+++*#=:#%%%%%#***-::...      :++*++++**************************+***#####**++=-.   ...:.:=**##%%%%%+:*#*+++.
negligible in economic value,   .+++*##:=%%%%%%#***:.:...      .=+**##***+++++*****************########****+++=-  ...:::=**##%%%%%#-=#*++=-
                                :*++*##:-%%%%%%##**=:.:...      -=+***#################%%%%%%%######******++++=:...::-+**##%%%%%*:+**++=-
it was never settled in the  .   +++**#=:*%%%%%%#***-:::....    .=++******##########################******++=-:..:-=**##%%%%%#=-+**++=:
five centuries after its         .+++*##-:#%%%%%%##***-:::....   .=++*******####################******++==---::=+**##%%%%%%--***++=-
discovery, until the landing      :+++**#+:=%%%%%%%%##**+-::::....:==+********###############****+++=====+++**###%%%%%#+-+**++==:
of the Encyclopedists....           -+++**#*--#%%%%%%%%##***+--:::..---===+++++++++++++++++++======++****###%%%%%%#=-=***++=-.
                                       :+++**##*--+%%%%%%%%%####***++++++==============+++++++****#####%%%%%%%+--+***++==:.
ENCYCLOPEDIA GALACTICA                   -=++***##+=-+*#%%%%%%%%%%%############***#############%%%%%%**+===+***++=--.
                                              :+=+****###*=-:-+#%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#+===+*##**+++===:.
                                                  .:-=++++*****#***++++++++===+++***************++++=-::.
                                                           .:-=====+++++++++++++++++======--:..
    """

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):      return TerminusStarMap
        if starmapBtn(stdscr,clicks):   return TerminusStarMap

        if tradeBtn(stdscr,clicks):
            return TerminusTrade

        stdscr.refresh()
        start = wait(start)
    return None

def TerminusBtn(stdscr,clicks,y,x):
    gazBtn = [
        "⠀⠀⠀⠀⢀⢤⣴⡶⠶⣤⡄⠀⠀⠀⠀⠀",
        "⠀⠀⠀⠐⠛⠻⠷⣦⣤⣤⣤⡿⠈⠳⣶⣄",
        "⠀⠀⠰⠿⠿⠷⢶⣦⣉⢉⣡⣶⠦⣠⣿⠏",
        "⢠⣾⠰⣤⣄⣀⠀⠉⠻⠿⣋⣤⡾⠟⠁⠀",
        "⢿⣿⣶⣬⣭⣭⣥⣶⠾⢛⣫⣥⠂⠀⠀⠀",
        "⠀⠀⠉⠉⠉⠐⠀⠼⠿⠛⠉⠀⠀⠀⠀⠀",
        "    Terminus",
        ]
    if button(stdscr,clicks,y-3,x-12,gazBtn):
        return True
    return False


def TerminusStarMap(stdscr,ctx):
    scene = """
 terminus             
              anacreon

               thespis
                      
     smyrno           
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    #prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Terminus 
        terminus_y, terminus_x = locate(scene ,"planet")
        if TerminusBtn(stdscr,clicks,terminus_y,terminus_x):
            return Terminus 

        if locateBtn(stdscr,clicks,scene ,"terminus"):   return Terminus
        if locateBtn(stdscr,clicks,scene ,"anacreon"):   return Anacreon
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"smyrbo"):     return Smyrno

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None



def TerminusTrade(stdscr,ctx):
    scene = """
                                              ━┏┛┏━┛┏━┃┏┏ ┛┏━ ┃ ┃┏━┛
                                               ┃ ┏━┛┏┏┛┃┃┃┃┃ ┃┃ ┃━━┃
                                               ┛ ━━┛┛ ┛┛┛┛┛┛ ┛━━┛━━┛
┏━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━┓
┃  ┏━┛┏━┃┏━┃┏━┛┏━┃ ┃┃  ┏━┛━┏┛┏━┃┏━┃┏━┃┏━┛┏━┛     ┃┃ ┏━┛┏━┃┏━┃┏━┛━┏┛ ┃
┃  ┃  ┏━┃┏┏┛┃ ┃┃ ┃ ┃┃  ━━┃ ┃ ┃ ┃┏┏┛┏━┃┃ ┃┏━┛     ┃┃ ┃  ┏┏┛┏━┃┏━┛ ┃  ┃
┃  ━━┛┛ ┛┛ ┛━━┛━━┛ ┃┃  ━━┛ ┛ ━━┛┛ ┛┛ ┛━━┛━━┛     ┃┃ ━━┛┛ ┛┛ ┛┛   ┛  ┃
┃ +       +        ┃┃ -        -        -        ┃┃ -               ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃ +       +        ┃┃ -        -        -        ┃┃ -               ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃ +       +        ┃┃ -        -        -        ┃┃ -               ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃ +       +        ┃┃ -        -        -        ┃┃ -               ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┃ $                ┃┃ -        -        -        ┃┃ -               ┃
┃                  ┃┃                            ┃┃                 ┃
┃                  ┃┃                            ┃┃                 ┃
┗━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━┛
    """
    scenePurified = re.sub(r"[+|\-|?|=|$]", ' ', scene)

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # this part from sqlite/context
    cargo = [
                Metal,
                PreciousMetal,
                RareMetal,
                FissibleMaterial,
            ] # space ship
    cargoMax = countChar(scene,'+')

    storage = [] + ([FissibleMaterial,]*1) + ([Metal,] * 2)

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)
        prnt(stdscr,0,0,scenePurified)

        if backBtn(stdscr,clicks):      return Terminus
        if starmapBtn(stdscr,clicks):   return TerminusStarMap

        # here it is unique
        # you store ressources
        # and craft technology with it
        # that you can then sell high price
        unload = placeProductsOn(stdscr,clicks,scene,'+',cargo)
        if unload:
            storage.append(unload)
            cargo.remove(unload)

        buy = placeProductsOn(stdscr,clicks,scene,'-',storage)
        if buy:
            cargo.append(buy)
            storage.remove(buy)


        # BiologicalTechnology
        # ForceField

        # NuclearTechnology
        if RareMetal in storage and FissibleMaterial in storage:
            if CraftBtn(stdscr,clicks,scene,NuclearTechnology):
                storage.append(NuclearTechnology)
                storage.remove(FissibleMaterial)
                storage.remove(RareMetal)


        # IndustrialTechnology
        if Metal in storage:
            if CraftBtn(stdscr,clicks,scene,IndustrialTechnology,1):
                storage.append(IndustrialTechnology)
                storage.remove(Metal)

        # MedicalTechnology
        if RareMetal in storage:
            if CraftBtn(stdscr,clicks,scene,MedicalTechnology,2):
                storage.append(MedicalTechnology)
                storage.remove(RareMetal)

        # LuxuryTechnology
        if RareMetal in storage and PreciousMetal in storage:
            if CraftBtn(stdscr,clicks,scene,LuxuryTechnology,3):
                storage.append(LuxuryTechnology)
                storage.remove(RareMetal)
                storage.remove(PreciousMetal)

        # ReligiousTechnology
        if RareMetal in storage and PreciousMetal in storage and FissibleMaterial in storage:
            if CraftBtn(stdscr,clicks,scene,ReligiousTechnology,4):
                storage.append(ReligiousTechnology)
                storage.remove(PreciousMetal)
                storage.remove(RareMetal)
                storage.remove(FissibleMaterial)

        stdscr.refresh()
        start = wait(start)
    return None

def CraftBtn(stdscr,clicks,scene,good,n=0):
    btn = [
        "┏━━━━━",
        "┃Craft",
        "┗━━━━━",
            ]
    y,x = findChar(scene,'=',n)
    if not x:
        return False
    if good(stdscr,clicks,y,x+6):
        return True
    if button(stdscr,clicks,y,x,btn):
        return True
    return False

# ______________ ANACREON ______________________

"""

THE FOUR KINGDOMS - The name given to those portions of the Province of Anacreon which 
broke away from the First Empire in the early years of the Foundational Era to form 
independent and short-lived kingdoms. The largest and most powerful of these was Anacreon 
itself which in area... 

... Undoubtedly the most interesting aspect of the history of the Four Kingdoms involves the 
strange society forced temporarily upon it during the administration of Salvor Hardin.... 

ENCYCLOPEDIA GALACTICA 
"""

def Anacreon(stdscr,ctx):
    scene = """
        Anacreon
┏━┃┏━ ┏━┃┏━┛┏━┃┏━┛┏━┃┏━                             .:::::..         
┏━┃┃ ┃┏━┃┃  ┏┏┛┏━┛┃ ┃┃ ┃                         .:+#%%%%%%#*-.      
┛ ┛┛ ┛┛ ┛━━┛┛ ┛━━┛━━┛┛ ┛                        :*%%%%%@%%%%%%#-.    
In the outer provinces,                       .-#%%%@@@@@@@@%%%%=.   
near Terminus.Former imperial               ..:+%%%@@@@@@@@@@%%%#-.  
province reduced to a feudal              .::-=#%%%@@@@@@@@@@@%%%=.  
nuclear kingdom.                       .-=*****#%%%%@@@@@@@@@@%%%=.  
Possesses advanced weapons           :+##%%%%%%%##%%%@@@@@@@@%%%*:.  
without understanding their         -*#%%%@@@@%%%%#%%%@@@@%%%%%#-.   
maintenance.                       :*#%%@@@@@@@@@%%#%%%%%%%%%%+:.    
Infrastructure decays while       .=#%%%@@@@@@@@@%%%##%%%%#+-:.      
political power rests on           -#%%@@@@@@@@@@%%##+=--:..         
superstition.                      :*#%%@@@@@@@@%%%#*-:.             
Anacreon illustrates                -##%%%@@@@@%%%#*-.               
technological regression and         :+##%%%%%%##*=:.                
the danger of inherited tools          :-+*****+-..                  
divorced from scientific                                             
comprehension.                                                       
                                                                   
                                                                   
                   :----:::::---====+=.                            
               .:......    . ...::::--==++:                        
            .                     ..::---==++-                     
          .                           ...:---=++                   
                                         .::--==+*                 
                                            .::--=+=               
                                              .::-=++              
                                                .::-=+:            
                                                  .:-=+:           
                                                   .::-=.          
                                                     .:=+          
                                                      .-=-         
                                                       :-=         
                                                       .:-:        
                                                        .:-        
                                                         .-        
                                                         .:        
                                                         .         
                                                                   


    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return AnacreonStarMap
        if backBtn(stdscr,clicks):      return AnacreonStarMap
        if tradeBtn(stdscr,clicks):     return AnacreonTrade

        stdscr.refresh()
        start = wait(start)
    return None

def AnacreonBtn(stdscr,clicks,y,x):
    gazBtn = [
        ".....................,,::,,,........",
        "...................,:=%%@%#-,,......",
        ".................,,-*%@@@@@%=,......",
        "...............,:=*#%.@@@@@@*:,.....",
        "..............,+%@@@@%.@@@@#-,......",
        ".............,:#@@@@@@%.*+-:,.......",
        "..............,+%@@@@%.-:,,.........",
        "...............,-+##*-..............",
        ".................,,,,...............",
        "....................................",
        ".......,-==--==++=,.................",
        "....,:,  ,,,,,,:--=++:..............",
        "                 ,:-=+*,............",
        "                    ,:=++...........",
        "                      ,-=-..........",
        "                       ,-+,.........",
        "                        ,-:.........",
        "                         :,.........",
        "       Anacreon          ,..........",
        ]
    if button(stdscr,clicks,y-9,x-17,gazBtn):
        return True
    return False

def AnacreonStarMap(stdscr,ctx):
    scene = """
 terminus                           
              thespis              

               anacreon
                                    
     smyrno                         
-                                   
                         helicon    
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Anacreon 
        anacreon_y, anacreon_x = locate(scene ,"anacreon")
        if AnacreonBtn(stdscr,clicks,anacreon_y,anacreon_x):
            return Anacreon 

        if locateBtn(stdscr,clicks,scene ,"terminus"):   return Terminus
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"smyrbo"):     return Smyrno
        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

def AnacreonTrade(stdscr,ctx):
    scene = """
                         ┏━┃┏━ ┏━┃┏━┛┏━┃┏━┛┏━┃┏━    ━┏┛┏━┃┏━┃┏━ ┏━┛
                         ┏━┃┃ ┃┏━┃┃  ┏┏┛┏━┛┃ ┃┃ ┃    ┃ ┏┏┛┏━┃┃ ┃┏━┛
                         ┛ ┛┛ ┛┛ ┛━━┛┛ ┛━━┛━━┛┛ ┛    ┛ ┛ ┛┛ ┛━━ ━━┛
┏━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  ┏━┛┏━┃┏━┃┏━┛┏━┃ ┃┃  ┏┏ ┏━┃┏━┃┃ ┃┏━┛━┏┛                ?                  ┃
┃  ┃  ┏━┃┏┏┛┃ ┃┃ ┃ ┃┃  ┃┃┃┏━┃┏┏┛┏┛ ┏━┛ ┃                                    ┃
┃  ━━┛┛ ┛┛ ┛━━┛━━┛ ┃┃  ┛┛┛┛ ┛┛ ┛┛ ┛━━┛ ┛                                    ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ $                ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┗━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    """
    scenePurified = re.sub(r"[+|\-|?|=|$]", ' ', scene)

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # this part from sqlite/context
    cargo = [NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,] # space ship
    cargoMax = countChar(scene,'+')

    wallet = 0  # player cash
    market = [] + ([FissibleMaterialBtn,]*10) + ([MetalBtn,] * 20)
    prices = {
            #may buy from terminus
            NuclearTechnologyBtn: 1000,
            BiologicalTechnologyBtn: 100,
            MedicalTechnologyBtn: 300,
            IndustrialTechnologyBtn: 500,
            ReligiousTechnologyBtn: 1000,
            ForceFieldBtn: 5000,
            LuxuryTechnologyBtn: 100,
            #willing to sell
            FissibleMaterialBtn:50,
            RareMetalBtn:300,
            PreciousMetalBtn:100,
            MetalBtn:10,
            }

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)
        prnt(stdscr,0,0,scenePurified)

        if backBtn(stdscr,clicks):      return Anacreon
        if starmapBtn(stdscr,clicks):   return AnacreonStarMap

        # feudal system, 
        # under anacreon authotity
        # planet have centralized market
        sell = placeProductsOnWithPriceTag(stdscr,clicks,scene,'+',cargo,prices)
        if sell in prices:
            market.append(sell)
            cargo.remove(sell)
            wallet += prices[sell]

        buy = placeProductsOnWithPriceTag(stdscr,clicks,scene,'-',market,prices)
        if buy in prices and len(cargo) < cargoMax:
            cargo.append(buy)
            market.remove(buy)
            wallet -= prices[buy]

        if balanceBtn(stdscr,clicks,scene,wallet):
            pass

        if wallet >= 0:
            if dealBtn(stdscr,clicks,scene):
                return AnacreonTrade

        stdscr.refresh()
        start = wait(start)
    return None

# ______________ THESPIS ______________________

def Thespis(stdscr,ctx):
    scene = """
         ..
      ...::...
     ..:-==-:..
     ..:-++-:..                                            ..........
      ...::...                             .::-::..     ....:::::::....
         ...                           .=***+++=====+-.  ::---===--:::...
                                     :++++=+==--::::-=++  -=++***++=-::...
━┏┛┃ ┃┏━┛┏━┛┏━┃┛┏━┛               .=+++==----:::....:-=** +*#%%%#+=--:...
 ┃ ┏━┃┏━┛━━┃┏━┛┃━━┃              .=+++=---=-::....  ..-=*# *#%@%#*+=-::..
 ┛ ┛ ┛━━┛━━┛┛  ┛━━┛              -=====--:::...      .:-=*# ****+==-::...
Peripheral kingdom, near        .=+===--:::...        .:-+#+ ====--::...
Anacreon and Terminus.          :==+==-:::..           .:=** ::::::....
                                 :==--:::...             :-++ ........
                                 .==--::...              .:=: .....
                                  :=-=-:..               .:-.
                                   :-::..                .:.
                                    .:..                 .
                                      ..
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):    return ThespisStarMap
        if backBtn(stdscr,clicks):      return ThespisStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def ThespisBtn(stdscr,clicks,y,x):
    gazBtn = [
        "....-=-......................................",
        "...+@%-.............................-:.......",
        "...:=:..............................--.......",
        "..................................--.........",
        "...............................:=====--......",
        "..............................=++======:.....",
        "...................-=*##*-...:+*++=====-.....",
        "..................:*###%%%*..-+**+=====:.....",
        "..................=####%%%#:..:+++====:......",
        "..................:*#%##%%*.....-:::-........",
        "..Thespis..........-=*##*-...................",
        ]
    if button(stdscr,clicks,y-5,x-18,gazBtn):
        return True
    return False

def ThespisStarMap(stdscr,ctx):
    scene = """
 terminus                           
              anacreon              

               thespis
                                    
     smyrno                         
-                                   
                         helicon    
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Thespis 
        thespis_y, thespis_x = locate(scene ,"thespis")
        if ThespisBtn(stdscr,clicks,thespis_y,thespis_x):
            return Thespis 

        if locateBtn(stdscr,clicks,scene ,"terminus"):   return Terminus
        if locateBtn(stdscr,clicks,scene ,"anacreon"):   return Anacreon
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"smyrbo"):     return Smyrno
        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None


def ThespisTrade(stdscr,ctx):
    scene = """
                             ━┏┛┃ ┃┏━┛┏━┛┏━┃┛┏━┛   ━┏┛┏━┃┏━┃┏━ ┏━┛
                              ┃ ┏━┃┏━┛━━┃┏━┛┃━━┃    ┃ ┏┏┛┏━┃┃ ┃┏━┛
                              ┛ ┛ ┛━━┛━━┛┛  ┛━━┛    ┛ ┛ ┛┛ ┛━━ ━━┛
┏━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  ┏━┛┏━┃┏━┃┏━┛┏━┃ ┃┃  ┏┏ ┏━┃┏━┃┃ ┃┏━┛━┏┛                ?                  ┃
┃  ┃  ┏━┃┏┏┛┃ ┃┃ ┃ ┃┃  ┃┃┃┏━┃┏┏┛┏┛ ┏━┛ ┃                                    ┃
┃  ━━┛┛ ┛┛ ┛━━┛━━┛ ┃┃  ┛┛┛┛ ┛┛ ┛┛ ┛━━┛ ┛                                    ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ $                ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┗━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    """
    scenePurified = re.sub(r"[+|\-|?|=|$]", ' ', scene)

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # this part from sqlite/context
    cargo = [NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,NuclearTechnologyBtn,] # space ship
    cargoMax = countChar(scene,'+')

    wallet = 0  # player cash
    market = [] + ([FissibleMaterialBtn,]*10) + ([MetalBtn,] * 20)
    prices = {
            NuclearTechnologyBtn: 1000,
            BiologicalTechnologyBtn: 100,
            MedicalTechnologyBtn: 300,
            IndustrialTechnologyBtn: 500,
            ReligiousTechnologyBtn: 1000,
            ForceFieldBtn: 5000,
            LuxuryTechnologyBtn: 100,

            FissibleMaterialBtn:50,
            RareMetalBtn:300,
            PreciousMetalBtn:100,
            MetalBtn:10,
            }

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)
        prnt(stdscr,0,0,scenePurified)

        if backBtn(stdscr,clicks):      return Thespis
        if starmapBtn(stdscr,clicks):   return ThespisStarMap

        # feudal system, 
        # under anacreon authotity
        # planet have centralized market
        sell = placeProductsOnWithPriceTag(stdscr,clicks,scene,'+',cargo,prices)
        if sell in prices:
            market.append(sell)
            cargo.remove(sell)
            wallet += prices[sell]

        buy = placeProductsOnWithPriceTag(stdscr,clicks,scene,'-',market,prices)
        if buy in prices and len(cargo) < cargoMax:
            cargo.append(buy)
            market.remove(buy)
            wallet -= prices[buy]

        if balanceBtn(stdscr,clicks,scene,wallet):
            pass

        if wallet >= 0:
            if dealBtn(stdscr,clicks,scene):
                return ThespisTrade

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ SNYRNO ______________________

def Smyrno(stdscr,ctx):
    scene = """
┏━┛┏┏ ┃ ┃┏━┃┏━ ┏━┃                                    ..:#@@*:.
━━┃┃┃┃━┏┛┏┏┛┃ ┃┃ ┃                              ..:--=+#%@@@@#*+=--:...
━━┛┛┛┛ ┛ ┛ ┛┛ ┛━━┛                           ..:=#@@@@@@@@@@@@@@@@@@%+-:.
In the mid-galaxy,                         .:*@@@@@@@@@@@@@@@@@@@@@@@@@@@=.
accessible to Foundation                 .=@@@@@@@@@+::-=++++=-:.=@@@@@@@@@#:
traders, not near the Core.            .*@@@@@#=*%%%#%@@@@@@@@@@@@@%#+-*@@@@@@=
Commercial world dominated            +@@@@-*@@@@@@@@@@@@@@@@@@@@@@@@@@@@+-@@@@@:
by traders and merchants.           .@@@@.%@%*+-. :*@@@@@@@##@@%%@@@@@@@@@@@:%@@@*
Politically flexible and           -@@@.@@@-:++::=#@@=.:==*%@@#**++++#@@@@@@@@%#@@#
economically motivated.           =@@%:%*=-+= +@@@@@=:.:=*#@@@*+=-:...:---+@@@@@+@@#
Smyrno highlights the rise       :@@-+*+: :*@@@@@@#+=+%@@%#+-:::..........:-+%@@@+@@=
of mercantile cultures after    .#@-*##*-:=#@@@%*-:=**+=:....  ...............:=%@+#@:
imperial collapse, where        =%:=++=-:----:..............       . ...........:+#:*+
loyalty follows profit and      *+:---::::.                                    ..:=+-+.
economic pragmatism replaces   .=-+-:.                                            .:-:.
ideological allegiance or      :::-:                                                ..
centralized authority.         :..
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return SmyrnoStarMap
        if backBtn(stdscr,clicks):      return SmyrnoStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def SmyrnoBtn(stdscr,clicks,y,x):
    gazBtn = [
        ".........---........",
        ".....-=+++++++=:....",
        "...-++**######**+:..",
        "..-=+**##%%%%%%#*+-.",
        "..=+*##%%%%@@@%%#*:.",
        "..-+**###%%%###**+-.",
        "...=+**#####*##**:..",
        "....-=++******+-....",
        "........----........",
        "........Smyro.......",
        ]
    if button(stdscr,clicks,y-5,x-10,gazBtn):
        return True
    return False


def SmyrnoStarMap(stdscr,ctx):
    scene = """
 terminus                         
              anacreon            

               thespis
                                  
     smyrno                       
-                                 
                         helicon  
                                  
                                  
                                  
-                     korell      
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Smyrno 
        smyrno_y, smyrno_x = locate(scene ,"smyrno")
        if SmyrnoBtn(stdscr,clicks,smyrno_y,smyrno_x):
            return Smyrno 

        if locateBtn(stdscr,clicks,scene ,"terminus"):   return Terminus
        if locateBtn(stdscr,clicks,scene ,"anacreon"):   return Anacreon
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon
        if locateBtn(stdscr,clicks,scene ,"korell"):     return Korell

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

def SmyrnoTrade(stdscr,ctx):
    scene = """
 here the prices will vary                            ━┏┛┏━┃┏━┃┏━ ┏━┛
 they will sell higher than they buy                   ┃ ┏┏┛┏━┃┃ ┃┏━┛
 the price will droo if you sell too much              ┛ ┛ ┛┛ ┛━━ ━━┛
┏━━━━━━━━━━━━━━━━━━┓┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓
┃  ┏━┛┏━┃┏━┃┏━┛┏━┃ ┃┃  ┏┏ ┏━┃┏━┃┃ ┃┏━┛━┏┛                ?                  ┃
┃  ┃  ┏━┃┏┏┛┃ ┃┃ ┃ ┃┃  ┃┃┃┏━┃┏┏┛┏┛ ┏━┛ ┃                                    ┃
┃  ━━┛┛ ┛┛ ┛━━┛━━┛ ┃┃  ┛┛┛┛ ┛┛ ┛┛ ┛━━┛ ┛                                    ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ +       +        ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┃ $                ┃┃ -        -        -        -        -        -        ┃
┃                  ┃┃                                                       ┃
┃                  ┃┃                                                       ┃
┗━━━━━━━━━━━━━━━━━━┛┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
    """
    scenePurified = re.sub(r"[+|\-|?|=|$]", ' ', scene)

    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()

    # this part from sqlite/context
    cargo = [NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,NuclearTechnology,] # space ship
    cargoMax = countChar(scene,'+')

    '''
    wallet = 0  # player cash
    market = [] + ([FissibleMaterial,]*10) + ([Metal,] * 20)
    prices = {
            NuclearTechnology: 1000,
            BiologicalTechnology: 100,
            MedicalTechnology: 300,
            IndustrialTechnology: 500,
            ReligiousTechnology: 1000,
            ForceField: 5000,
            LuxuryTechnology: 100,
            FissibleMaterial:50,
            Metal:10,
            PreciousMetal:100,
            RareMetal:500,
            }
    '''
    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)
        prnt(stdscr,0,0,scenePurified)

        if backBtn(stdscr,clicks):      return StarMap
        if starmapBtn(stdscr,clicks):   return StarMap

        # here is a decentralised market
        # that mean you have several buyer/seller
        # free market / capitalism
        # will sell higher than they buy
        # the more they stock, the lower they buy/sell
        # when you buy, the prices go down
        '''
        sell = placeProductsOnWithPriceTag(stdscr,clicks,scene,'+',cargo,prices)
        if sell in prices:
            market.append(sell)
            cargo.remove(sell)
            wallet += prices[sell]

        buy = placeProductsOnWithPriceTag(stdscr,clicks,scene,'-',market,prices)
        if buy in prices and len(cargo) < cargoMax:
            cargo.append(buy)
            market.remove(buy)
            wallet -= prices[buy]

        if balanceBtn(stdscr,clicks,scene,wallet):
            pass

        if wallet >= 0:
            if dealBtn(stdscr,clicks,scene):
                return StarMap
        '''

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ HELICON ______________________

def Helicon(stdscr,ctx):
    scene = """
┃ ┃┏━┛┃  ┛┏━┛┏━┃┏━                                         ..:::-----:::..
┏━┃┏━┛┃  ┃┃  ┃ ┃┃ ┃                                   .-===++++++++++++++++==--:
┛ ┛━━┛━━┛┛━━┛━━┛┛ ┛                               .:==++****##****+++******+++===--.
In the inner regions,                          ::-=++*%%%@@@@#******#*++++=--++=====-:
relatively close to Trantor.                 :-=++**#%@@@@@@@@@%##***+++**+++++++++===-:.
Agrarian, mountainous world                 -=+**#*###@@@@@@@@@@@@@@@@%*+***+++++++++===-:.
with conservative traditions              -=+*###%%@@@@@@@@@@@@@@@@@@@@%******++++++++====-:
and limited technology.                  -+**#%%%%@@@@@@@@@@@@@@@@@@%%%%#*+++***+++++=++====-.
Birthplace of Hari Seldon.              =+*##%%#%@@@@@@@@@@@@@@@@@%%%%%**++++*+*+++++==++++==-:
Its rural stability contrasts          =+*#%%%%%@@@@@@@@@@@@@@@@%%%%%%%%%*****+++++++++++=====-:
with Trantor’s artificiality,         -+*#%%%@@@@@@@@@@@@@@@@%%%%%%%%%%%%%*******+**++=+====-=--.
reinforcing the Foundation theme      +*##%%@@@@@@@@@@@@@@@%%%%%%%%%%%%%%#******++***++====-----:
that historical insight and          :*##%%@@@@@@@@@@@@@@@%%%%%%%%%%%#####***++*+++*+----==-:::.
adaptability arise more easily       =*#%%@@@@@@@@@@@@@@@%%%%%%#%%%%%#####***++++++==-::-::::::
from the periphery than imperial    =+##%%@@@@@@@@@@@@@@%%%%%%#%%%%%######****++++==-:.:. .....
centers.                            =*##%%@@@@@@@@@@@@@%%%%%%%%%%%%########**#*+++=.: .:.  ..
                                    =*#%%%@@@@@@@@@@@@@%%%%%%%%%########**####**++=-:  ...        .:
                                    -+##%%@@@@@@@@@@@@@%%%%%%%%%#######**###****+++=-: ..         --
                                     +*#%%@@@@@@@@@@@@@@%%%%%%%%########%#******++++-:.::.  .    -+-
                                     =*##%%@@@@@@@@@@@@@%%%%%%%%%#%%####*********+++=: ..   .   .:=:
                                      +*#%%#@@@@@@@@@@@@@%%%%%%%%%######******++++++=:.       .. :-
                                      -+*#%###@@@@@@@@@@@%%%%%%%%%#***###****++++++==-:      :   -:
                                       -+**###%#%@@%@@@@@%%%%%%#******###****++++++==:: ..   .+*+-
                                       :-+**#%%@@%###****%%%##*+++++****#**#*+++++==-::..::-+**+-.
                                        .:=**#%%@@@%******++++++++++**+++++++++++=+*====--:=**+=.
                                          :=+*##%%%%%%%#+++++++++++++++*##*#%%%%#*#%+-----:+*+-
                                           .-++*#%%%%%%%%%#++++++++*%%%%%%#%%%%%%%%##*=----+=-
                                             :=+*##%%%%%%%%%%%%%%%%%%%%%%%%%%%%%######*+*+=-.
                                               :=+*###%%%%%%%%%%%%%%%%%%%%%%%%######***+=-.
                                                 :=+**####%%%%%%%%%%%%%%%%%######***++=-.
                                                   .-=+***#########%#########****++=-:
                                                      .-=++******######******+++=-:
                                                         ..:-===+++++++++===-:.
                                                                 .......
        """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return HeliconStarMap
        if backBtn(stdscr,clicks):      return StarMap

        stdscr.refresh()
        start = wait(start)
    return None

def HeliconBtn(stdscr,clicks,y,x):
    gazBtn = [
        "    :=+**+*+=:      ",
        "  =+#%@@@%%*++=-    ",
        "  *%@@@@@%%**++==   ",
        " +%@@@@%%%##*+-::   ",
        " *%@@@%%%###*+..  . ",
        " =#%@@@%%##**+:  .  ",
        "  =#%#**+****+--+-  ",
        "   :+#%%%%%%%#*=.   ",
        "     .=+****+-      ",
        "      Helicon",
        ]
    if button(stdscr,clicks,y-5,x-10,gazBtn):
        return True
    return False

def HeliconStarMap(stdscr,ctx):
    scene = """
anacreon                      

 thespis
                              
           helicon            
                              
                       trantor
                              
        korell                
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Helicon 
        helicon_y, helicon_x = locate(scene ,"helicon")
        if HeliconBtn(stdscr,clicks,helicon_y,helicon_x):
            return Helicon 

        if locateBtn(stdscr,clicks,scene ,"anacreon"):   return Anacreon
        if locateBtn(stdscr,clicks,scene ,"thespis"):    return Thespis
        if locateBtn(stdscr,clicks,scene ,"korell"):     return Korell
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ KORELL ______________________

"""

KORELL-.. 
.And so after three years of a war which was certainly the most unfought war on 
record, the Republic of Korell surrendered unconditionally, and Hober Mallow took his place 
next to Hari Seldon and Salvor Hardin in the hearts of the people of the Foundation. 

ENCYCLOPEDIA GALACTICA 
"""

def Korell(stdscr,ctx):
    scene = """
Korell
┃ ┃┏━┃┏━┃┏━┛┃  ┃  
┏┛ ┃ ┃┏┏┛┏━┛┃  ┃  
┛ ┛━━┛┛ ┛━━┛━━┛━━┛
In the mid-galactic regions, 
closer to Terminus than to 
Trantor. Industrial planet 
economically dependent on 
Foundation technology. 
Nominally independent 
but strategically controlled 
through trade monopolies. 
Korell represents the shift 
from military domination to 
economic leverage, showing 
how power in the post-Empire 
era is exercised through 
supply chains rather than armies.
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return KorellStarMap
        if backBtn(stdscr,clicks):      return KorellStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def KorellBtn(stdscr,clicks,y,x):
    gazBtn = [
            "[o]         ",
            "  \\_Korell",
        ]
    if button(stdscr,clicks,y,x,gazBtn):
        return True
    return False


def KorellStarMap(stdscr,ctx):
    scene = """
   helicon            
                      
               trantor
                      
korell                
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Korell 
        korell_y, korell_x = locate(scene ,"korell")
        if KorellBtn(stdscr,clicks,korell_y,korell_x):
            return Korell 

        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

# _______________ SYNNAX ______________________
"""
nebuleuse bleue
still connected to trantor
"""
# ______________ TRANTOR ______________________

"""
    
TRANTOR— . . . The capital of the First Galactic Empire . . . Under Cleon I, it had 
its “twilight glow.” To all appearances, it was then at its peak. Its land surface of 200 
million square kilometers was entirely domed (except for the Imperial Palace area) and 
underlaid with an endless city that extended beneath the continental shelves. The 
population was 40 billion and although the signs were plentiful (and clearly visible in 
hindsight) that there were gathering problems, those who lived on Trantor undoubtedly 
found it still the Eternal World of legend and did not expect it would ever . . . 

ENCYCLOPEDIA GALACTICA 


TRANTOR- ... It is almost never pictured as a world seen from space. It has 
long since captured the general mind of humanity as a world of the interior and the image 
is that of the human hive that existed under the domes. Yet there was an exterior as well 
and there are holographs that still remain that were taken from apace and show varying 
degrees of devil (see Figures 14 and 15 ). Note that the surface of the domes, the interface 



of the vast city and the overlying atmosphere, a surface referred to in its time as 
“Upperside, “ is . . . 

ENCYCLOPEDIA GALACTICA 


TRANTOR By the middle of the Interregnum, Trantor was a shadow. In the midst of the 
colossal ruins, there lived a small community of farmers.... 

ENCYCLOPEDIA GALACTICA 


WYE- ... A sector of the world-city of Trantor ... In the latter centuries of the 
Galactic Empire, Wye was the strongest and stablest portion of the world-city. Its rulers 
had long aspired to the Imperial throne, justifying that by their descent from early 



Emperors. Under Mannix IV, Wye was militarized and (Imperial authorities later 
claimed) was planning a planet-wide coup . 


ENCYCLOPEDIA GALACTICA 

MYCOGEN- ... A sector of ancient Trantor Buried in the past of its own legends 
Mycogen made little impact on the planet. Self-satisfied and self-separated to a degree . . 

ENCYCLOPEDIA GALACTICA 

MYCOGEN- . . . The microfarms of Mycogen are legendary, though they survive 
today only in such oftused similes as “rich as the microfarms of Mycogen” or “tasty as 
Mycogenian yeast.” Such encomiums tend to intensify with time, to be sure, but Hari 
Seldon visited those microfarms in the course of The Flight and there are references in 
his memoirs that would tend to support the popular opinion . . . 

ENCYCLOPEDIA GALACTICA 


SUNMASTER FOURTEEN- ... A leader of the Mycogen Sector of ancient 
Trantor ... As is true of all the leaders of this ingrown sector, little is known of him. That 
he plays any role at all in history is due entirely to his interrelationship with Hari Seldon 
in the course of The Flight . . . 


ENCYCLOPEDIA GALACTICA 

DAHL- . . . Oddly enough, the best-known aspect of this sector is Billibotton, a 
semi-legendary place about which innumerable tales have grown up. In fact, a whole 
branch of literature now exists in which heroes and adventurers (and victims) must dare 



the dangers of passing through Billibotton. So stylized have these stories become that the 
one well-known and, presumably, authentic tale involving such a passage, that of Hari 
Seldon and Dors Venabili, has come to seem fantastic simply by association . . . 


ENCYCLOPEDIA GALACTICA 



NEOTRANTOR The small planet of Dellcass, renamed after the Great Sack, was for nearly a 
century, the seat of the last dynasty of the First Empire. It was a shadow world and a shadow 
Empire and Its existence Is only of legalistic importance. Under the first of the Neotrantorlan 
dynasty.... 

ENCYCLOPEDIA GALACTICA 

STREELING UNIVERSITY—. . . An institution of higher learning in the 
Streeling Sector of ancient Trantor . . . Despite all these claims to fame in the fields of the 
humanities and silences alike, it is not for those that the University looms large in today’s 
consciousness. It would probably have come as a coral surprise to the generations of 
scholars at the University to know that in lacer times Streeling University would be most 
remembered because a certain Hari Seldon, during the period of The Flight, had been in 
residence there for a shore time. 

ENCYCLOPEDIA GALACTICA 
"""

def Trantor(stdscr,ctx):
    scene = """
                                                                              
                                                                              
━┏┛┏━┃┏━┃┏━ ━┏┛┏━┃┏━┃                                                        
 ┃ ┏┏┛┏━┃┃ ┃ ┃ ┃ ┃┏┏┛                                          --+-+-+++-+---.                               
 ┛ ┛ ┛┛ ┛┛ ┛ ┛ ━━┛┛ ┛                                     .--        .--        .-.                          
                                                      -++--           ..          .-+-.                      
Near the galactic center.                        .--...               ..              ..-..                  
Galactic capital and                            +-                    .                    --                
ultimate ecumenopolis.                        -.                     ...                     ..              
Entire surface covered                      -.                      ....                       -.            
in metal, housing tens                     -                 ......--++--........                -           
of billions dependent on                 ..             ....-+###+-+-+###++#+-......              -          
imported food.                          .             ...-#+++++---++++++++--+---.....             .         
Administrative complexity              ..            ..+++##+-+##+###+#--++++------.....            -        
masks deep fragility.                  .           ..-----#--###+#+#+++++#+--....----....            .       
Trantor embodies imperial             .            .-----+###+#+-##++++++++.+---------...             .      
peak and decay simultaneousl         .            .-----++-+-++##+-+#+#++-+#-..--..-.--...                   
proving that centralized             .          ..-++#--+##+-##++#########+--+-...---.---.            ..     
power collapses once                -.        . .-----.--++--.+#+#--###+-+++#----......--..            .     
logistical balance is lost.        ...       ...-+-#+...-----+##+###+++++++++++-----....-....           -    
                                    ...    ....-.----...... -.--.-++++---+--------   .......--...-.     ..    
                                   .--+---.... ..---.......-.--+#++++##++##++----.  ..............    ...    
                                   .--          .-++-....----.+++-++++#++-++++----..-.....        ....-+-    
                                   ..           .-.-.....-..+++--+-++-+-+---+--........--...           .-    
                                    ..           ..... ....--+++--+--+---+--+++....  ...                .    
                                    ..           .... .......----+--------++--......                   .     
                                     .            .......... -----++++-++--+-... ..                   ..     
                                     .             ......... ......-.-.-......   .                    .      
                                      .              ......   .   .  ..                               .      
                                       .              . .. .  ..  .     .  .....                     .       
                                        .                   ....   . . .    .                                
                                        .                      ..   . .                                      
                                         ..                                                       -          
                                           -                                                    .-           
                                            ..                                                 +             
                                              -.                                             -.              
                                               .-.                                        .+-                
                                                   .--.                               ..-.                   
                                                      .-+-.          .            -++-.                      
                                                          .--       .--        .--.                          
                                                              ..--+++++++-...                               

    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return TrantorStarMap
        if backBtn(stdscr,clicks):      return TrantorStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def TrantorBtn(stdscr,clicks,y,x):
    gazBtn = [
        "      :: ::   ::    ",
        "    :    :;      ;  ",
        "   :  *==:*::=    ::",
        "  :  ==:**;=;:::   :",
        "  ::=*=---=:*::;*;::",
        "  : ==:***==*+=:=  :",
        "   :  ;::::::::    ;",
        "    :    :::    =+  ",
        "      =+ :====*=    ",
        "       Tranto",
        ]
    if button(stdscr,clicks,y-5,x-10,gazBtn):
        return True
    return False

def TrantorStarMap(stdscr,ctx):
    scene = """
                           aurora
                                 
   helicon                       
                                 
               trantor           
                                 
korell                           
                                 
                      rossem     
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Trantor 
        trantor_y, trantor_x = locate(scene ,"trantor")
        if TrantorBtn(stdscr,clicks,trantor_y,trantor_x):
            return Trantor 

        if locateBtn(stdscr,clicks,scene ,"helicon"):    return Helicon
        if locateBtn(stdscr,clicks,scene ,"korell"):     return Korell
        if locateBtn(stdscr,clicks,scene ,"rossem"):     return Rossen 
        if locateBtn(stdscr,clicks,scene ,"aurora"):     return Aurora 

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ EARTH ______________________

def Earth(stdscr,ctx):
    scene = """
                                                    
┏━┛┏━┃┏━┃━┏┛┃ ┃                                  ##########                     
┏━┛┏━┃┏┏┛ ┃ ┏━┃                             .####-+#########+###                
━━┛┛ ┛┛ ┛ ┛ ┛ ┛                           ########################-             
                                        -.####-##################+-#+           
Original human homeworld.             -  .##########################+           
Once temperate, biologically         #### ####  ++-####################         
rich, and technologically           +####.#####+     ######.########. .         
central. Political decline         -#####--##        -#+    .##### .    .       
and radioactive contamination      +-###++####- .     #+-..  .#.+# #--###       
reduced it to obscurity.           #+..-#### ####+...#  .     -#-   #  .#.      
By the Foundation era it is        ++...##    -.+              ##++#+.##--      
forgotten or mythologized,         -#..+#               +##+    ###  +.##.      
illustrating how civilizations      . .-+    .#  #-#        #+ .#  # - -#       
erase their own origins while         ....  # #       .    -      +-  ---       
expanding across the galaxy.          ..   --  #  .                ###++        
                                       -    +  +####             ######         
                                         .+#       .  +##+ -     +###-          
                                          -+-+++-. .     .##-    .+#.           
                                             ...-+#.--.    ###+--+              
                                                .-..---+ +#####.                
                                                      .- .                      

    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return EarthStarMap
        if backBtn(stdscr,clicks):      return EarthStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def EarthBtn(stdscr,clicks,y,x):
    gazBtn = [
        "        _____",
        "    ,-:` \\;',`'-, ",
        "  .'-;_,;  ':-;_,'.",
        " /;   '/    ,  _`.-\\",
        "| '`. (`     /` ` \\`|",
        "|:.  `\\`-.   \\_   / |",
        "|     (   `,  .`\\ ;'|",
        " \\     | .'     `-'/",
        "  `.   ;/        .'",
        "jgs `'-._____.",
        "         Earth",
        ]
    if button(stdscr,clicks,y-5,x-12,gazBtn):
        return True
    return False


def EarthStarMap(stdscr,ctx):
    scene = """
                         earth
 solaria                       
                              


      aurora             + 
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Earth 
        earth_y, earth_x = locate(scene ,"earth")
        if EarthBtn(stdscr,clicks,earth_y,earth_x-26):
            return Earth 

        if locateBtn(stdscr,clicks,scene ,"aurora"):     return Aurora 
        if locateBtn(stdscr,clicks,scene ,"solaria"):    return Solaria

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ AURORA ______________________

"""

AURORA- ... A mythical world, supposedly inhabited in primordial times, 
during the dawn of interstellar travel. It is thought by some to he the perhaps equally 
mythical “world of origin” of humanity and to be another name for “Earth.” The people 
of the Mycogen (q.v.) Sector of ancient Trantor reportedly held themselves to be 
descended from the inhabitants of Aurora and made that tenet central to their system of 
beliefs, concerning which almost nothing else is known . . . 


ENCYCLOPEDIA GALACTICA 

"""

def Aurora(stdscr,ctx):
    scene = """
┏━┃┃ ┃┏━┃┏━┃┏━┃┏━┃                              .-*+--+**+++#*+::.
┏━┃┃ ┃┏┏┛┃ ┃┏┏┛┏━┃                          :=+++++++++++==--:----=+=.
┛ ┛━━┛┛ ┛━━┛┛ ┛┛ ┛                       :=+++++++++++++++++++========+=.
Leading Spacer world                  .-++****************+++====-------==.
with advanced robotics               -+++*************+++++++++++++=--------.
and long-lived inhabitants.        .=+++++++**********++++++++====+++=--::----.
Culturally stagnant and           -+=++++++*+**##%##**+++**+++*+++++++==------=.
hostile toward Earth-born        -+++**+++++***##%#**++++++++++**+++++====----=+.           .:=:
humans. Represents early        :+++**+++++*********+++++++++++*+++=======-----==.          :=*##-
galactic elitism and the       .=++**##*+**+++++++++++++++++++++++++=======-----==.         :=*#%%
divergence between slow,       =+++*###*+++**+++++++++++++++******+=--=-====---===:        .-+*#%#.
perfection-oriented Spacer    .++*+*#%%*++***+++++++++++++++++****++===-=++=====++-.        .:::.
societies and the dynamic,    :++*++*#*+++***##**++++++***+++++++++====-===+===+++=.
expansionist Settler worlds   -++*+++====+*##%%##***##*****+*++++++++++======++++==.
that eventually eclipse them. -+++*+====++++*###%#*###**++*****+****+++++==++++++==.
                              :++*+++++++*****###*++**#######*******++===++++++====.
                              :++***++++***#****++++*#######*******++++++=+++++==--
                               +******++**###+****+++*#####*****#***++++========--:
                               .********************##*+++++***+*#**+++=========  ....:.
                                -*#*****#**+*****#****++==+++++++**+++========- .:=-=++++-.
                                 -*###**###+++*++**#%#*====+++++===+++===-=-== -=++++++++*+.
                                  -***#*****#*+*++*++**++++++++++======-===== ===+++++*****+
                                   .+*+****+*+***********++++==========--=-== :==++++**##**=
                                     -+****++++*****++++++==========--------: .-++++***##+*-
                                      .-==++++++****+++============------=:     -++*******=.
                                         :=====+++*++++==---==----=-=-==.         .-++=-.
                                            :=====+==+++++======++++=.
                                                .-+++==========-:.
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return AuroraStarMap
        if backBtn(stdscr,clicks):      return AuroraStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def AuroraBtn(stdscr,clicks,y,x):
    gazBtn = [
        "           :::               ",
        "      ++**++++=---.          ",
        "   .++******++===: .         ",
        "  -+***#%%+++***+=-::-     . ",
        " .*%%+**++=++*#*----::.    +@",
        " +*+++#%#*+***+==--====      ",
        " +*=+*#%@+#%%%##*==++=-      ",
        " :##*#@*#**%###%*+--=-       ",
        "  *%#%***%@===-=++::-.  **   ",
        "   .**+*###**===--::.: +%#-  ",
        "     .==+*+-::::::.    ++.   ",
        "         ..::.               ",
        "        Aurore               ",
        ]
    if button(stdscr,clicks,y-6,x-15,gazBtn):
        return True
    return False

def AuroraStarMap(stdscr,ctx):
    scene = """
                               earth
      solaria                       
                                    

            aurora             + 
                                    
                                    
 trantor                             
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Aurora 
        aurora_y, aurora_x = locate(scene ,"aurora")
        if AuroraBtn(stdscr,clicks,aurora_y,aurora_x):
            return Aurora 

        if locateBtn(stdscr,clicks,scene ,"earth"):      return Earth
        if locateBtn(stdscr,clicks,scene ,"solaria"):    return Solaria
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ AURORA ______________________


def Solaria(stdscr,ctx):
    scene = """
┏━┛┏━┃┃  ┏━┃┏━┃┛┏━┃                                ......::::::::-::-:.
━━┃┃ ┃┃  ┏━┃┏┏┛┃┏━┃                              ......::::-------------:.
━━┛━━┛━━┛┛ ┛┛ ┛┛┛ ┛                              ......::::-----==========--.
                                               .......:::::-------===========-:
Extremely low-population                       ......::::::-----------=========-:
Spacer planet built around                   .......::::::----------=============-.
radical isolation. Humans                    .....:::::----------==================-
live alone, interacting                     .....::::-------=======================--.
almost exclusively through                 .....::::-----=======+++++++++++++++++===--:
robots and holography.                   ......:::------======+++++++***+++++++++++===-:
Social contact is considered             .....:::::-----=======+++++***********++++++==-:
repulsive. Solaria shows how             .....::::::-----======+++++***************+++==-.
technological abundance and             ......:::::------====++++++++*****#####*****+++==-.
fear of others can drive               ......::::------======+++++++++***###########**++==-
humanity toward self-inflicted         .....:::::------=====+++++*******#############**++=-.
extinction.                            .....:::-------=====++++++******################*+==-
                                      .....:::::-----=====++++++*****#*################**+=-.
                                      .....::::::----=====++++++****###########%%%######*++=:
                                      .....::::::----=====++++++****##########%%%%%%####**+=:
                                      .....:::::-----=======++++*****#######%%%#%%%%%###**+=-
                                      ......::::-----=======++++*****#######%%%%%%%%%###**+=-
                                      ......::::-----=======+++++****#######%%%%%%%%####**+=-
                                      ......::::----=========++++*****######%%%%#%%#####**+=-
                                       .....::::-----========+++++*****##########%####***++=:
                                       .....::::--------=====+++++*******###########*****+=-.
                                       ......::::-------======+++++******###########****+==-
                                        ......:::::------======++++*******************++==-.
                                         ......:::::------====+++++++**************++++===-
                                          ......:::::-----====+++++++++++++++++++++++====-.
                                          ......:::::-----====++++++++++++++++++++++=====:
                                          ......:::::-----=============++++++++++++++===:
                                          ......:::::-----------======+++++++++++++++==:
                                           ......::::::-------=======+++++++++++++++==:
                                            .......::::::-----=======+++++++++++++==-.
                                             ......::::-----=============+=+++++===-
                                             ......:::::----------=========+=====-.
                                             .......::::::-------=============--:
                                               ......:::::--------==========--:
                                                ......:::::---------=======-:
                                                 .....:::::-----========-:
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return SolariaStarMap
        if backBtn(stdscr,clicks):      return SolariaStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def SolariaBtn(stdscr,clicks,y,x):
    gazBtn = [
        "          ..:::::.        ",
        "         ..:::------      ",
        "        ..::---------:    ",
        "      ..::---==++++===-.  ",
        "      ..::--===++****+=-. ",
        "     ..::--==+++***##**+- ",
        "     ..::--==+***######*=.",
        "     ..::-===++*#######*+:",
        "     ..:--===++**##%%%#*+-",
        "     ..:----==+***####**+:",
        "      ..::--==++*******+-.",
        "       ..::-===+++++++==: ",
        "       ..::----====+===:  ",
        "        ..::---=======:   ",
        "        ..:::----==-:     ",
        "         ..::-----:       ",
        "      Solarie             ",
        ]
    if button(stdscr,clicks,y-8,x-5,gazBtn):
        return True
    return False

def SolariaStarMap(stdscr,ctx):
    scene = """
                                 earth
        solaria                       
                                      
                                      
                          

              aurora             + 
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Solaria 
        solaria_y, solaria_x = locate(scene ,"solaria")
        if SolariaBtn(stdscr,clicks,solaria_y,solaria_x):
            return Solaria 

        if locateBtn(stdscr,clicks,scene ,"aurora"):     return Aurora 
        if locateBtn(stdscr,clicks,scene ,"earth"):      return Earth

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

# ______________ GAIA ______________________
"""
"""

def Gaia(stdscr,ctx):
    scene = """
┏━┛┏━┃┛┏━┃                                                     .:--=======-:                                 
┃ ┃┏━┃┃┏━┃                                              . .:--:::............:::::-----:.                        
━━┛┛ ┛┛┛ ┛                                        .==---::...  .         ...:::---:---::.
Planetary collective                           :===-----....               ....:---:---::--.
consciousness where all                     .=-====-----:..                 ...::-------::--.:.
life shares a unified mind.               =:==-=-====-----:.     ...:::...     ...:-----------.....
Individual identity exists              :=---:---=====----..  .:--======--:.   ..:-=----:---:..... .
but is subordinate to                  +++++++++========-::. .===+++====+===:. ..----------..:::......
planetary awareness. Gaia             ===========-===-----...===-====+======-:..:----::::::::.........
proposes an alternative             -------------:.---====-.:::--:..==-.:::-::..:-::::::.::::::.......
evolutionary path for              -=--------::.--::=-:-=--::--::-:::-:.::--:::.::.::::::::::. ....
humanity, challenging both        =====--==---------------::--:.....:+:..---.:::....::...........
imperial authoritarianism        :-=--==-----=-=----------:-==++**=-.=-.:=++-:....:.....:...... ..
and Foundation technocracy       =======---------==------:---:=====::*-.:-==--..::. ...........   ..
with enforced harmony and       :===--====--------------::..:::-==+-.. .=+*+=:.......:::::. ...  .
collective decision-making.     --========----=====-==-:...:::::----:..:==--:.:--....:::::...  ...
                                -=--=+=-:----:.:-====::-:...:::.==. :--. ..-.:.:: ......:...:::....
                                :-===--==----:.:-:----:.....  ...:..........:..:...........:::..
                                :------------:.::::::::.....   .-:..:::.::..    . ........-::..
                                .:--------:--::.:.::::::....   .. :..:.:..:..       ....::::....
                                 :-::::::---::::.:........:..     .-::::.  .          ....:::... .
                                 .:::------::::...:::...:::..      ......              ....... ..
                                  ::::::::::::.::::.......::                   .... . .. ... ..
                                   :-----::::--....::---::.     ..  .....       .... .
                                    ::::::---:..    .....  .    ::..........     ...... .               .
                                     :--------.. .....        ..::::::::..... .   .  .      .
                                       :::---:.:     .    ..::.:-:-:..:.............                 .
                                        .................:::.......:::..:...........   .                      
                                           .......::::.......:::::...................                         
                                           . .:..............................   .  ..         .               
                                             .............................  .                 .               
                                              ................  ...                 ..                        
                                                ....  ............      ....::..                              
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return GaiaStarMap
        if backBtn(stdscr,clicks):      return GaiaStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def GaiaBtn(stdscr,clicks,y,x):
    gazBtn = [
        "       ...         ",
        "   .::.      ...   ",
        "  :--         .::  ",
        " :--.===:  -+-:-:. ",
        ".:-=:*#+=..*%*+::. ",
        " :--.          -:..",
        ".:---:.:.   ..:-::.",
        ".:---:.:*++-.:-:::.",
        " .:---:.:-:..:-::. ",
        "   --+=-:::-==-:.  ",
        "   =+=-=+++==-==   ",
        "       ++++        ",
        "       Gaïa        ",
        ]
    if button(stdscr,clicks,y-6,x-10,gazBtn):
        return True
    return False

def GaiaStarMap(stdscr,ctx):
    scene = """
                      - 
                      +
                         - 
          gaia   + 
                      + 
                      + 
               +
   tazenda            + 
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Gaia 
        gaia_y, gaia_x = locate(scene ,"gaia")
        if GaiaBtn(stdscr,clicks,gaia_y,gaia_x):
            return Gaia 

        if locateBtn(stdscr,clicks,scene ,"tazenda"):    return Tazenda

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None

# ______________ STARS END ______________________
def StarEnd(stdscr,ctx):
    scene = """
    Star’s End

┏━┛━┏┛┏━┃┏━┃┛┏━┛  ┏━┛┏━ ┏━          . .   .....:--:.                                                
━━┃ ┃ ┏━┃┏┏┛ ━━┃  ┏━┛┃ ┃┃ ┃         ..  . ...:.:==::=-:.                                            
━━┛ ┛ ┛ ┛┛ ┛ ━━┛  ━━┛┛ ┛━━          ... . .:--:----==+-::-.                                         
At the far edge of the galaxy,          ...:--::==:-=*=---==-                                       
                                     :.   ....:-:-::---+-++*==.                                     
                                     . . .....::-:::---=-=++=-::.                                   
                                        .....:..:-=-:+--++#*=---+=                                  
                                        ..:: ...:.-:--===-+*==-=---.                                
                                      ....--::--:..--====+*#*=---:==.                               
                                     ....:.:----::-=--=**#**+*-:=-=-=.                              
                                  .........::----:---=+:+#+*+*===++*+*:                             
                              .... . ...:.-::::.--:--:==+#***+=:+=---#%.                            
                              . . .   ......:::----::--++##*+=++*++=++**                            
                               .:   ... ......::.:=--=+===--=***=+++**++-                           
                                .  .........:::::----:..-=--=*+#+=++*#*++                           
                                      .    ..:.:==-=:::.-+-===+#+=+***##*.                          
                                      .    ..:-=--=-:-:-:=++-++*=++=+*=*+=                          
                                     ..  . .:-:=---=::-:-==**=+*+===**=+*+                          
                               .... ..:..::.:::.:.:-:::==++===+#++==**=++*                          
                                . .::.::--=-:::.-=--=-:-=====+==-*+=**+*++                          
                                  . .... .:--::-==---.:.+-+===+====+**+%*=                          
                                 ....::....::-:=::::-----=-++++=++*#*#*##:                          
                               .........:..:...::::::::---=+++*+=+%#####%:                          
                                 ..:....:..:::.::-::::=.--:=++*++++#%#%##                           
                                   ......:::::---::::::.:----+---++*###%=                           
                                .. ....:-:::::-:.:::-:=---=-=----==+*%#%.                           
                                  .........:::-::::::::-====-=--==---=*:                            
                                 ... :.:..-:.::.-=:::-::-===-=-:=+==:-.                             
                                  .. ..:..:.::-:::.::---===-=*-===+--:                              
                                   ..:..::.:-:..:::::::=---========-:                               
                                ........:-:----.:-.::..:::-::::---:.                                
                               ....::::::::-:--....:::::-=-----:::                                  
                              . ......:-:-::--:=:::::::--=+=::.:.                                   
                              ........::::::::--:--:::--++=:-:.                                     
                               .......:::---::--:-----=-====                                        
                                 .:....:::::-:::.::.:::-:.                                          
                                    .....:::.-:::=:--:.                                             
                                   . .:..:-::::.-:.                                                 
                                   ....:......                                                      


    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return StarEndStarMap
        if backBtn(stdscr,clicks):      return StarEndStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def StarEndBtn(stdscr,clicks,y,x):
    gazBtn = [
        ".....--    --+......",
        "...--       --+#-...",
        "..---      ---++##..",
        "..-       ----+###-.",
        "..        ---+####+.",
        "..--     ---+#####-.",
        "..--------++######..",
        "...+#++++#######+...",
        "....-+########+.....",
        "....Star's End......"
        ]
    if button(stdscr,clicks,y-5,x-10,gazBtn):
        return True
    return False

def StarEndStarMap(stdscr,ctx):
    scene = """
 tazenda            + 
                    + 
                    +
                    - 
     starend      + 
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return StarEnd 
        starend_y, starend_x = locate(scene ,"starend")
        if StarEndBtn(stdscr,clicks,starend_y,starend_x):
            return StarEnd 

        if locateBtn(stdscr,clicks,scene ,"tazenda"):    return Tazenda

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ ROSSEM ______________________
def Rossem(stdscr,ctx):
    scene = """
    Rossem
┏━┃┏━┃┏━┛┏━┛┏━┛┏┏ 
┏┏┛┃ ┃━━┃━━┃┏━┛┃┃┃
┛ ┛━━┛━━┛━━┛━━┛┛┛┛
Cold, remote, sparsely 
populated planet. Used 
as a deliberate false 
trail to mislead enemies 
searching for the Second 
Foundation. Rossem 
exemplifies misdirection 
and strategic obscurity, 
reinforcing the recurring 
Foundation motif that true 
power often hides behind 
deliberate insignificance.
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return RossemStarMap
        if backBtn(stdscr,clicks):      return RossemStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def RossemBtn(stdscr,clicks,y,x):
    gazBtn = [
            "[o]         ",
            "  \\_Rossem",
        ]
    if button(stdscr,clicks,y,x,gazBtn):
        return True
    return False

def RossemStarMap(stdscr,ctx):
    scene = """


  trantor                          
                                 
                                 
                          tazenda
                                 
                                 
       rossem                    
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Rossem 
        rossem_y, rossem_x = locate(scene ,"rossem")
        if RossemBtn(stdscr,clicks,rossem_y,rossem_x):
            return Rossem 

        if locateBtn(stdscr,clicks,scene ,"tazenda"):    return Tazenda
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor
        if locateBtn(stdscr,clicks,scene ,"korell"):     return Korell

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None
# ______________ TAZENDA ______________________
def Tazenda(stdscr,ctx):
    scene = """
    Tazenda
━┏┛┏━┃━━┃┏━┛┏━ ┏━ ┏━┃
 ┃ ┏━┃┏┛ ┏━┛┃ ┃┃ ┃┏━┃
 ┛ ┛ ┛━━┛━━┛┛ ┛━━ ┛ ┛
Mountainous, harsh world 
believed to host the Second 
Foundation. Serves as an 
intentional decoy. Its 
physical remoteness and 
severe environment support 
the illusion, demonstrating 
how geography and myth are 
exploited to manipulate 
perception in galactic-scale 
psychological strategy.
    """
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if starmapBtn(stdscr,clicks):   return TazendaStarMap
        if backBtn(stdscr,clicks):      return TazendaStarMap

        stdscr.refresh()
        start = wait(start)
    return None

def TazendaBtn(stdscr,clicks,y,x):
    gazBtn = [
            "[o]         ",
            "  \\_Tazenda",
        ]
    if button(stdscr,clicks,y-1,x,gazBtn):
        return True
    return False

def TazendaStarMap(stdscr,ctx):
    scene = """
trantor                              
                                     
                                     
                          tazenda    
                                     
                                     
       rossem                        
                              starend
    """.replace(' ','   ').replace('\n','\n\n')
    keys, clicks = getNpt(stdscr)    # flush input
    start = time.time()
    stdscr.clear()
    prnt(stdscr,3,1,scene )

    exited = False
    while not exited:
        keys, clicks = getNpt(stdscr)
        exited = gtfo(stdscr,keys,clicks,1,70)

        if backBtn(stdscr,clicks):
            return Tazenda 
        tazenda_y, tazenda_x = locate(scene ,"tazenda")
        if TazendaBtn(stdscr,clicks,tazenda_y,tazenda_x):
            return Tazenda 

        if locateBtn(stdscr,clicks,scene ,"rossem"):     return Rossem 
        if locateBtn(stdscr,clicks,scene ,"starend"):    return StarEnd
        if locateBtn(stdscr,clicks,scene ,"trantor"):    return Trantor

        stdscr.addstr(1,20,"starmap")

        stdscr.refresh()
        start = wait(start)
    return None


#################################################
############### Hyper Space #####################
#################################################
def HyperSpace(stdscr,ctx):
    scene = """

                                                   .                                                
                                                                                                    
                                                       *                                            
                                                                                                    
        *                                                                                        * 
                           *                                     .                                  
                                         *                                                         
                        *                                                                           
                    .                                                                               
                                                                   .                                
                                                                   *                                
                         .   *       *                   *                                         
                                                                                                    
                              *                                                                     
                                                                       .                            
                                                        *                                 *       
                                 *                          *                                     
                                                                                                    
                                               .                                                    
                                        *      .                     .            *                 
                                                                                                    
                                      .                                                             
                                                                                                    
                                                                                                    
                                                                                                    
    """
    start = time.time()
    stdscr.clear()
    prnt(stdscr,0,0,scene )

    fps = 15

    # frame 1
    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
     =======           ============================
   ====================================================
  ==________________________        ________________========
  ==______________________            ___________________=====
  ==   -----------------               ||||                 ====
  ==     ---------------               ||||                  ===
  ==       -------------               ||||              ///====
  ===_____________________            ////            ///======
    ==______________________       /////         /////=====
                       ===============      /////=======
                         =============  ////=======
                                    ==========
                                    =======
         """)
    stdscr.refresh()
    start = wait(start,15)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                    =====         =====================
  _______________  =======================================
                  =__________________      ____________======
                  =_________________         ______________====
                  =   ------------            |||            ===
                  =    -----------            |||             ==
                  =      ---------            |||          //===
  ______________  ==________________         ///         //=====
                   ==________________      ///       ////====
                                  ===========    ////=====
                                   ========== ///======
                                           ========
                                           ======
         """)
    stdscr.refresh()
    start = wait(start,fps)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                        ====        ==================
  __________________  ===================================
                      =________________     ___________=====
                      =_______________        ____________====
                      =  -----------          |||           ===
                      =   ----------          |||            ==
                      =     --------          |||         //===
  _________________   ==______________        //        //====
                       =_______________     ///      ///====
                                    ==========    ///=====
                                     ========= ///====
                                            =======
                                            =====
         """)
    stdscr.refresh()
    start = wait(start,fps)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                                  ===      ==============
      _________________________  ==========================
                                =____________    ________====
                                =___________      __________==
                                =  --------        ||        ==
                                =   -------        ||         =
                                =    ------        ||       /==
      _________________________ ==__________      //      //===
                                 =___________    //     //===
                                           =======   ///===
                                            ====== //====
                                                 =====
           """)
    stdscr.refresh()
    start = wait(start,fps)



    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                                  ===      ==============
      _________________________  ==========================
                                =____________    ________====
                                =___________      __________==
                                =  --------        ||        ==
                                =    ------        ||       /==
      _________________________ ==__________      //      //===
                                 =___________    //     //===
                                           =======   ///===
                                                 =====
           """)
    stdscr.refresh()
    start = wait(start,fps)


    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                                       ===    ===========
          __________________________  =====================
                                     =_________     ________==
                                     =  ------       ||      ==
                                     =    ----       ||     /==
          __________________________ ==________     //    //===
                                      =_________   //   //===
                                              ======   /===
                                                   ====
           """)
    stdscr.refresh()
    start = wait(start,fps)

    # frame 2
    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                                        ===    ===========
            _________________________  =====================
                                      =_________     ________=
                                      =  ------       ||      =
                                      =    ----       ||     /=
            _________________________ ==________     //    //==
                                               ======   //==
                                                    ====
         """)
    stdscr.refresh()
    start = wait(start,fps)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,6,0,"""
                                             ===   ========
                __________________________  ================
                                           =________    _____=
                                           =  -----      |    =
                                           =    ---      |   /=
                __________________________ ==_______    //  /==
                                                   =====  /=
                                                       ===
         """)
    stdscr.refresh()
    start = wait(start,fps)

    # frame 3
    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                   ____________________________   _   _______
                                                 =============
                                                 _  ====  |___=
                   ____________________________  =_______/   /=
                                                         ===
         """)
    stdscr.refresh()
    start = wait(start,fps)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                           ______________________   _   ______
                                                   ============
                           ______________________  =______/   /
                                                          ===
         """)
    stdscr.refresh()
    start = wait(start,fps)

    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                               ____________________   _  ____
                                                     =========
                               ____________________  =____/  /
                                                          ==
         """)
    stdscr.refresh()
    start = wait(start,fps)


    # frame 4
    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                           __________________________   _  __
                           __________________________  ====O==
                                                          ///
         """)
    stdscr.refresh()
    start = wait(start,fps)


    # frame 5
    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                               ___________________________ =o>
         """)
    stdscr.refresh()
    start = wait(start,fps)


    # frame 6
    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                                         ____________        X
         """)
    stdscr.refresh()
    start = wait(start,fps)

    # frame 7
    prnt(stdscr,0,0,scene )
    prnt(stdscr,7,0,"""
                                            ____            +
         """)
    stdscr.refresh()
    start = wait(start,fps)
    return None



#################################################
############ Encyclopedia Galactica #############
#################################################

"""

* All quotations from the Encyclopedia Galactica here reproduced are taken from the 1 1 6th 
Edition published in 1020 F.E. by the Encyclopedia Galactica Publishing Co., Terminus, with 
permission of the publishers. 


"""

"""

HARI SELDON-... bom In the 1 1,988th year of the Galactic Era; died 12,069. The dates are 
more commonly given In terms of the current Foundational Era as - 79 to the year 1 F.E. Born 
to middle-class parents on Flelicon, Arcturus sector (where his father, In a legend of doubtful 
authenticity, was a tobacco grower in the hydroponic plants of the planet), he early showed 
amazing ability in mathematics. Anecdotes concerning his ability are innumerable, and some 
are contradictory. At the age of two, he is said to have ... 

... Undoubtedly his greatest contributions were in the field of psychohistory. Seldon found the 
field little more than a set of vague axioms; he left it a profound statistical science.... 

... The best existing authority we have for the details of his life is the biography written by Gaal 
Dornick who. as a young man, met Seldon two years before the great mathematician's death. 
The story of the meeting ... 

ENCYCLOPEDIA GALACTICA* 



"""

"""


PSYCHOHISTORY-.. .Gaal Dornick, using nonmathematical concepts, has defined 
psychohistory to be that branch of mathematics which deals with the reactions of human 
conglomerates to fixed social and economic stimuli.... 

... Implicit in all these definitions is the assumption that the human conglomerate being dealt 
with is sufficiently large for valid statistical treatment. The necessary size of such a 
conglomerate may be determined by Seldon 's First Theorem which ...A further necessary 
assumption is that the human conglomerate be itself unaware of psychohistoric analysis in 
order that its reactions be truly random ... 

The basis of all valid psychohistory lies in the development of the Seldon. Functions which 
exhibit properties congruent to those of such social and economic forces as ... 

ENCYCLOPEDIA GALACTICA 


5 . 


"""

"""

COMMISSION OF PUBLIC SAFETY-... The aristocratic coterie rose to power after the 
assassination of Cleon I, last of the Entuns. In the main, they formed an element of order during 
the centuries of instability and uncertainty in the Imperium. Usually under the control of the 
great families of the Chens and the Divarts, it degenerated eventually into a blind instrument for 
maintenance of the status quo.... They were not completely removed as a power in the state 
until after the accession of the last strong Emperor, Cleon H. The first Chief Commissioner.... 

... In a way, the beginning of the Commission's decline can be traced to the trial of Fiari Seldon 
two years before the beginning of the Foundational Era. That trial is described in Gaal Dornick's 
biography of Fiari Seldon.... 

ENCYCLOPEDIA GALACTICA 



"""

"""






BEL RIOSE .... In his relatively short career, Riose earned the title of "The Last of the Imperials'' 
and earned It well. A study of his campaigns reveals him to be the equal of Peurifoy in strategic 
ability and his superior perhaps in his ability to handle men. That he was born in the days of the 
decline of Empire made it all but impossible for him to equal Peurifoy's record as a conqueror. 
Yet he had his chance when, the first of the Empire's generals to do so, he faced the 
Foundation squarely.... 

ENCYCLOPEDIA GALACTICA* 


"""

"""

FOUNDATION ... With forty years of expansion behind them, the Foundation faced the menace 
of Riose. The epic days of Hardin and Mallow had gone and with them were gone a certain 
hard daring and resolution.... 

ENCYCLOPEDIA GALACTICA 


"""

"""

CLEON II commonly called "The Great. " The last strong Emperor of the First Empire, he is 
important for the political and artistic renaissance that took place during his long reign. He is 
best known to romance, however, for his connection with Bel Riose, and to the common man, 
he is simply "Riose's Emperor. " It is important not to allow events of the last year of his reign to 
overshadow forty years of... 


ENCYCLOPEDIA GALACTICA 


"""

"""
THE MULE Less is known of "The Mule" than of any character of comparable significance to 
Galactic history. Even the period of his greatest renown is known to us chiefly through the eyes 
of his antagonists and, principally, through those of a young bride.... 

ENCYCLOPEDIA GALACTICA 



"""

"""



THE MULE It was after the fall of the First Foundation that the constructive aspects of the 
Mule's regime took shape. After the definite break-up at the first Galactic Empire, it was he who 
first presented history with a unified volume at space truly imperial in scope. The earlier 
commercial empire at the fallen Foundation had been diverse and loosely knit, despite the 
impalpable backing at the predictions of psycho-history. It was not to be compared with the 
tightly controlled 'Union of Worlds' under the Mule, comprising as it did, one-tenth the volume of 





the Galaxy and one-fifteenth of its population. Particularly during the era of the so-called 
Search.... 

ENCYCLOPEDIA GALACTICA * 


"""

"""



Seldon's Plan 

MATHEMATICS The synthesis of the calculus of n-variables and of n-dimensional geometry is 
the basis of what Seldon once called "my little algebra of humanity".... 

ENCYCLOPEDIA GALACTICA 


"""

"""



19 

End of War 

QUORISTON, BATTLE OF Fought on 9, 17, 377 F.E. between the forces of the Foundation 
and those of Lord Stettin of Kalgan, it was the last battle of consequence during the 
Interregnum .... 

ENCYCLOPEDIA GALACTICA 


"""

"""

VENABILI, DORS—. . . Historian, born in Cinna . . . Her life might well have 
continued on its uneventful course were it not for the face that, after she had spent two 
years on the faculty of Streeling University, she became involved with the young Hari 
Seldon during The Flight . . . 

ENCYCLOPEDIA GALACTICA 

"""

"""






LEGGEN, JENARR- . . . His contributions to meteorology, however, although 
considerable, pale before what has ever since been known as the Leggen Controversy. 
That his actions helped to place Hari Seldon in jeopardy is undisputable, but argument 



rages— and has always raged— as to whether those actions were the result of unintentional 
circumstance or part of a deliberate conspiracy. Passions have been raised on both sides 
and even the most elaborate studies have come to no definite conclusions. Nevertheless, 
the suspicions that were raised helped poison Leggen’s career and private life in the years 
that followed . . . 

ENCYCLOPEDIA GALACTICA 

"""

"""



HAND-ON-THIGH STORY-. . . An occasion cited by Hari Seldon as the first 
turning point in his search for a method to develop psychohistory. Unfortunately, his 
published writings give no indication as to what that “story” was and speculations 
concerning it (there have been many) are futile. It remains one of the many intriguing 
mysteries concerning Seldon’s career. 

ENCYCLOPEDIA GALACTICA 

"""

"""

ROBOT- ... A term used in the ancient legends of several worlds for what are 
more usually called “automata.” Robots are described as generally human in shape and 
made of metal, although some are supposed to have been pseudoorganic in nature. Hari 
Seldon, in the course of The Flight, is popularly supposed to have seen an actual robot, 
but that story is of dubious origin. Nowhere in Seldon’ s voluminous writings does he 
mention robots at all, although . . . 

ENCYCLOPEDIA GALACTICA 


"""

"""
AMARYL, YUGO- ... A mathematician who, next to Hari Seldon himself, may 
be considered most responsible for working out the details of psychohistory. It was he 
who . . . 

... Yet the conditions under which he began life are almost more dramatic than 
his mathematical accomplishments. Born into the hopeless poverty of the lower classes of 
Dahl, a sector of ancient Tractor, he might have passed his life in utter obscurity were it 
not for the fact that Seldon, quite by accident, encountered him in the course of . . . 

ENCYCLOPEDIA GALACTICA 


"""

"""


DAVAN- ... In the unsettled times marking the final centuries of the First 
Galactic Empire, the typical sources of unrest arose from the fact that political and 
military leaders jockeyed for “supreme” power (a supremacy that grew more worthless 



with each decade). Only rarely was there anything that could be called a popular 
movement prior to the advent of psychohistory. In this connection, one intriguing 
example involves Davan, of whom little is actually known, but who may have met with 
Hari Seldon at one time when . . . 

ENCYCLOPEDIA GALACTICA 

"""

"""
RAYCH- . . . According to Hari Seldon, the original meeting with Raych was 
entirely accidental. He was simply a gutter urchin from whom Seldon had asked 
directions. But his life, from that moment on, continued to be intertwined with that of the 
great mathematician until . 


ENCYCLOPEDIA GALACTICA 



"""

"""

THALUS, EMMER- ... A sergeant in the armed security forces of the Wye 
Sector of ancient Trantor . . . 

. . . Aside from these totally unremarkable vital statistics, nothing is known of the 
man except that on one occasion he held the fate of the Galaxy in his fist. 

ENCYCLOPEDIA GALACTICA 

"""

"""

SELDON, HARI- ... It is customary to think of Hari Seldon only in connection 
with psychohistory, to see him only as mathematics and social change personified. There 
is no doubt that he himself encouraged this for at no time in his formal writings did he 
give any hint as to how he came to solve the various problems of psychohistory. His 
leaps of thought might have all been plucked from air, for all he tells us. Nor does he tell 
us of the blind alleys into which he crept or the wrong turnings he may have made . 

... As for his private life, it is a blank. Concerning his parents and siblings, we 
know a handful of factors, no more. His only son, Raych Seldon, is known to have been 
adopted, but how that came about is not known. Concerning his wife, we only know that 
she existed. Clearly, Seldon wanted to be a cipher except where psychohistory was 
concerned. It is as though he felt— or wanted it to be felt-that he did not live, he merely 
psychohistorified. 

ENCYCLOPEDIA GALACTICA 


"""

"""



VENABILI, DORS—. . . Historian, born in Cinna . . . Her life might well have 
continued on its uneventful course were it not for the face that, after she had spent two 
years on the faculty of Streeling University, she became involved with the young Hari 
Seldon during The Flight . . . 

VENABILI, DORS- The life of Hari Seldon is well encrusted with legend and uncertainty, so that 
little hope remains of ever obtaining a biography that can be thoroughly factual. Perhaps the most 
puzzling aspect of his life deals with his consort, Dors Venabili. There is no information whatever 
concerning Dors Venabili, except for her birth on the world of Cinna, prior to her arrival at Streeling 
University to become a member of the history faculty. Shordy after that, she met Seldon and remained 
his consort for twenty-eight years. If anything, her life is more interlarded with legend than Seldon's 
is. There are quite unbelievable tales of her strength and speed and she was widely spoken of, or 
perhaps whispered of, as "The Tiger Woman." Still more puzzling than her coming, however, is her 
going, for after a certain time, we hear of her no more and there is no indication as to what happened. 

Her role as a historian is evidenced by her works on- 

ENCYCLOPEDIA GALACTICA 
ENCYCLOPEDIA GALACTICA 

"""

"""
CLEON I- . . . Though often receiving panegyrics for being the last Emperor under whom the First 
Galactic Empire was reasonably united and reasonably prosperous, the quarter-century reign of 
Cleon I was one of continuous decline. This cannot be viewed as his direct responsibility, for the 
Decline of the Empire was based on political and economic factors too strong for anyone to deal with 
at the time. He was fortunate in his selection of First Ministers-Eto Demerzel and then Hari Seldon, in 
whose development of psycho history the Emperor never lost faith. Cleon and Seldon, as the objects 
of the final Joranumite Conspiracy, with its bizarre climax- 

ENCYCLOPEDIA GALACTICA 

"""

"""

SELDON, WANDA- ... In the waning years of Hari Seldon's life, he grew most attached to (some 
say dependent upon) his granddaughter, Wanda. Orphaned in her teens, Wanda Seldon devoted herself 
to her grandfather's Psychohistory Project, filling the vacancy left by Yugo Amaryl 

The content of Wanda Seldon's work remains largely a mystery, for it was conducted in virtually 
total isolation. The only individuals allowed access to Wanda Seldon's research were Hari himself 
and a young man named Stettin Palver (whose descendant Preem would four hundred years later 
contribute to the rebirth of Trantor, as the planet rose from the ashes of the Great Sack [300 F.E.l). 

Although the full extent of Wanda Seldon's contribution to the Foundation is unknown, it was 
undoubtedly of the greatest magnitude 

ENCYCLOPEDIA GALACTICA 


"""

"""

VENABILI, DORS- The life of Hari Seldon is well encrusted with legend and uncertainty, so that 
little hope remains of ever obtaining a biography that can be thoroughly factual. Perhaps the most 
puzzling aspect of his life deals with his consort, Dors Venabili. There is no information whatever 
concerning Dors Venabili, except for her birth on the world of Cinna, prior to her arrival at Streeling 
University to become a member of the history faculty. Shordy after that, she met Seldon and remained 
his consort for twenty-eight years. If anything, her life is more interlarded with legend than Seldon's 
is. There are quite unbelievable tales of her strength and speed and she was widely spoken of, or 
perhaps whispered of, as "The Tiger Woman." Still more puzzling than her coming, however, is her 
going, for after a certain time, we hear of her no more and there is no indication as to what happened. 

Her role as a historian is evidenced by her works on- 

ENCYCLOPEDIA GALACTICA 

"""

"""

SELDON, HARI- . . . found dead, slumped over his desk in his office at Streeling University in 
12,069 G.E. (1 F.E.). Apparendy Seldon had been working up to his last moments on psychohistorical 

equations; his activated Prime Radiant was discovered clutched in his hand 

According to Seldon's instructions, the instrument was shipped to his colleague Gaal Dornick who 
had recently emigrated to Terminus 

Seldon's body was jettisoned into space, also in accordance with instructions he'd left. The official 
memorial service on Trantor was simple, though well attended. It is worth noting that Seldon's old 
friend former First Minister Eto Demerzel attended the event. Demerzel had not been seen since his 
mysterious disappearance immediately following the Joranumite Conspiracy during the reign of 
Emperor Cleon I. Attempts by the Commission of Public Safety to locate Demerzel in the days 

following the Seldon memorial proved to be unsuccessful 

Wanda Seldon, Hari Seldon's granddaughter, did not attend the ceremony. It was rumored that she 
was grief-stricken and had refused all public appearances. To this day, her whereabouts from then on 
remain unknown 

It has been said that Hari Seldon left this life as he lived it, for he died with the future he created 

unfolding all around him 

ENCYCLOPEDIA GALACTICA 

"""

"""


SELDON, WANDA- ... In the waning years of Hari Seldon's life, he grew most attached to (some 
say dependent upon) his granddaughter, Wanda. Orphaned in her teens, Wanda Seldon devoted herself 
to her grandfather's Psychohistory Project, filling the vacancy left by Yugo Amaryl 

The content of Wanda Seldon's work remains largely a mystery, for it was conducted in virtually 
total isolation. The only individuals allowed access to Wanda Seldon's research were Hari himself 
and a young man named Stettin Palver (whose descendant Preem would four hundred years later 
contribute to the rebirth of Trantor, as the planet rose from the ashes of the Great Sack [300 F.E.l). 

Although the full extent of Wanda Seldon's contribution to the Foundation is unknown, it was 
undoubtedly of the greatest magnitude 

ENCYCLOPEDIA GALACTICA 



"""

"""

CLEON I- . . . Though often receiving panegyrics for being the last Emperor under whom the First 
Galactic Empire was reasonably united and reasonably prosperous, the quarter-century reign of 
Cleon I was one of continuous decline. This cannot be viewed as his direct responsibility, for the 
Decline of the Empire was based on political and economic factors too strong for anyone to deal with 
at the time. He was fortunate in his selection of First Ministers-Eto Demerzel and then Hari Seldon, in 
whose development of psycho history the Emperor never lost faith. Cleon and Seldon, as the objects 
of the final Joranumite Conspiracy, with its bizarre climax- 

ENCYCLOPEDIA GALACTICA 
"""

"""

Arcadia 

DARELL, ARKADY novelist, born 1 1, 5, 362 F.E., died 1, 7, 443 F.E. Although primarily a writer 
of fiction, Arkady Darell is best known for her biography of her grandmother, Bayta Darell. 

Based on first-hand information, it has for centuries served as a primary source of information 
concerning the Mule and his times. ... Like "Unkeyed Memories", her novel "Time and Time and 
Over" is a stirring reflection of the brilliant Kalganian society of the early Interregnum, based, it 
is said, on a visit to Kalgan in her youth.... 

ENCYCLOPEDIA GALACTICA 
"""




if __name__ == "__main__":


    def main(stdscr):
        curses.curs_set(0)              # hide cursor
        curses.mousemask(curses.ALL_MOUSE_EVENTS | curses.REPORT_MOUSE_POSITION)
        stdscr.nodelay(True)            # non-blocking input
        stdscr.clear()
        # clean input
        keys = getCh(stdscr)
        clicks = getMouse(keys)


        ctx = {}
        co = Gaz

        while co:
            co = co(stdscr,ctx)


    curses.wrapper(main)



