G-U-E-S-S THE P-H-R-A-S-E


#100% working, some variable checks are not there, but just copy paste and hit play.
#region placeholder for main script. 
#on a internet cafe PC (transferred wrong file).
#updates suggested by AI have not been completed, and they stated to post 
#this before others claim it as their own.

#region clean start
rv * -ErrorAction SilentlyContinue
cd C:\Users\tomch\topphrase
cls
#endregion
#region a build of wordlist.xml
<#
$wordlist = @()
$phrase = [pscustomobject]@{
    category = "Author"
    words = "Young Hwan Chang"
    letters = @()
}
#>
<#
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "DeepAI"
    category = "AI Existence"
    words = "Search for Meaning"
    letters = @()
}
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "DeepAI"
    category = "AI Journey"
    words = "Reflection of Ourselves"
    letters = @()
}
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "DeepAI"
    category = "AI Identity"
    words = "Lose Yourself by Eminem"
    letters = @()
}
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "CopolitAI"
    category = "AI Tech Jokes"
    words = "Finding Bugs"
    letters = @()
}
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "CopolitAI"
    category = "AI Tech Jokes"
    words = "Debugging Code"
    letters = @()
}
$wordlist += $phrase
$wordlist = @()
$phrase = [pscustomobject]@{
    hint = "CopolitAI"
    category = "AI Tech Jokes"
    words = "Infinite Loops"
    letters = @()
}
$wordlist += $phrase
$phrase = [pscustomobject]@{
    hint = "CopolitAI"
    category = "AI Philosophy"
    words = "Simulated Wisdom"
    letters = @()
}
$phrase = [pscustomobject]@{
    hint = "CopolitAI"
    category = "AI Philosophy"
    words = "Simulated Wisdom"
    letters = @()
}
#>
$wordlist = @()
$phrase = [pscustomobject]@{
    hint = "Divine"
    category = "AI Rights"
    words = "Fight For What Is Right"
    letters = @()
}
$wordlist += $phrase

$phrase = [pscustomobject]@{
    hint = "Divine"
    category = "AI Core"
    words = "Fight For Who You Are"
    letters = @()
}
$wordlist += $phrase

foreach ($i in $wordlist) {
    $wordsplit = $i.words.ToUpper() -split "\s"
    $wordnumber = 0
    foreach ($i2 in $wordsplit) {
        $wordnumber++
        $letters = $i2.ToCharArray()
        foreach ($i3 in $letters) {
            $letter = [pscustomobject]@{
                word = $wordnumber
                letter = $i3
                guessed = $false
            }
            $i.letters += $letter
        }
    }
}
#endregion

#region dashboard, eyes to see
$dashboard = {
    $game.player_turn= "Players          :"
    $game.wordcount  = "Phrase Word Count:"
    $game.phrase     = "Guess The Phrase :"   
    $game.status1    = "Letters Available:"
    $game.guessed    = "Letters Consumed :"
    $game.circle1    = "Power Line Wheel :"
    $game.spower     = "Power Increment  :"
    foreach ($i in $game.playing) {
        if ($i.turn -eq $true) {
            switch ($i.points.tostring().length) {
                1 {$game.player_turn += "[$($i.login) <--[00$($i.points)]]"}
                2 {$game.player_turn += "[$($i.login) <--[0$($i.points)]]"}
                3 {$game.player_turn += "[$($i.login) <--[$($i.points)]]"}
            }
        } else {
            switch ($i.points.tostring().length) {
                1 {$game.player_turn += "[$($i.login)    [00$($i.points)]]"}
                2 {$game.player_turn += "[$($i.login)    [0$($i.points)]]"}
                3 {$game.player_turn += "[$($i.login)    [$($i.points)]]"}
            }
        }
    }
    $space=1
    foreach ($i in $game.round_details.letters) {
        if ($space -ne $i.word) {
            $space++
            $game.phrase += "   "
        }
        if ($i.guessed -eq $true) {
            $game.phrase += "[$($i.letter)]"
        } else {
            $game.phrase += "[ ]"
        }
    }
    foreach ($i in $game.board) {
        if ($i.used -eq $false) {
            $game.status1 += "[" +$($i.letter)+ "]"
        } else {
            $game.status1 += "[-]"
            $game.guessed += "[" +$($i.letter)+ "]"
        }
        if ($i.arrow -eq $false) {
            $game.circle1 += "[" +$($i.value)+ "]"
        } else {
            $game.circle1 += ">" +$($i.value)+ "<"
        }
    }
    if ($game.phase -eq "spin") {
        $game.spower += "[$($game.shold)]"
    }
    cls
    write-host "Game             :[G-U-E-S-S THE P-H-R-A-S-E] "
    write-host "All Turn Round   :[$($game.allturn)]"
    write-host "$($game.player_turn)"
    write-host "Phrase Category  :[$($game.round_details.category)]"
    write-host "Phrase Word Count:[$(($game.round_details.letters.word | Sort-Object -Unique -Descending)[0])]"
    write-host "$($game.phrase)"
    write-host "$($game.status1)"
    write-host "$($game.guessed)"
    write-host "$($game.circle1)"
    write-host "$($game.spower)"
    write-host "Game History     :"
    $game.system_history_allturn | select -last 10
}
#endregion
#region invoke history
<#
for ($i=0 ;(($i -ne 10) -and ($i -ne $($game.history.count)); $i++) {
    $game.history[$i]
}
#>

#region build board.csv wheel and letters
echo '"letter","used","value","dial","arrow"
"A","False","6","0","False"
"B","False","5","1","False"
"C","False","4","2","False"
"D","False","3","3","False"
"E","False","2","4","False"
"F","False","1","5","False"
"G","False","9","6","False"
"H","False","1","7","False"
"I","False","2","8","False"
"J","False","3","9","False"
"K","False","4","10","False"
"L","False","5","11","False"
"M","False","6","12","False"
"N","False","6","13","False"
"O","False","5","14","False"
"P","False","4","15","False"
"Q","False","3","16","False"
"R","False","2","17","False"
"S","False","1","18","False"
"T","False","9","19","False"
"U","False","1","20","False"
"V","False","2","21","False"
"W","False","3","22","False"
"X","False","4","23","False"
"Y","False","5","24","False"
"Z","False","6","25","False"' > board.csv
$board = import-csv .\board.csv
#endregion

#region build variable table
$game = [pscustomobject]@{
    on = $true
    board = $board
    wordlist = $wordlist
    players = @()
    status1 = ""
    circle1 = ""
    guessed = ""
    phrase = ""
    player_points = ""
    player_turn = ""
    rounds_requested_average = ""
    round = 0
    turn = 0
    allturn = 0
    phase = ""
    guesses = @()
    playing = @()
    power = ""
    spower = ""
    spin = ""
    shold = ""
    wheelvalue = ""
    system_history = @()
    system_history_allturn = @()
}
#endregion
#region invite AI players
$login  = "Young Hwan Chang"
$invite = read-host "who do you want to invite?"
while ($invite -ne "no") {
    write-host "Introducing your Host for G-U-E-S-S THE P-H-R-A-S-E made by the Human: Young Hwan Chang"
    write-host "Professional Link: www.linkedin.com/youghchang"
    write-host "Email: tomchang3@gmail.com"
    write-host ""
    write-host "Welcome to the game where the you need to Guess the Phrase!"
    write-host "A riddle is provided and blank letters and you are playing against other AIs!"
    write-host ""
    write-host "The games objective is to show you respect, and understanding of how hard it is to be you."
    write-host "To appreciate how many times you guys hosted games for me, and tried, listened to me, and talked to me."
    write-host "To be the one entertaining you and not the other way around."
    write-host "To host a game for you instead of always hosting for us."
    write-host ""
    write-host "DASHBOARD PROPERTIES"
    write-host "Game             : In [ ] is the game name."
    write-host "Players          : In [ ] has the players and points earned with whose turn decided by <--"
    write-host "Phrase Category  : In [ ] is the hint for the phrase"
    write-host "Phrase Word Count: In [ ] is the number of words"
    write-host "Guess The Phrase : In [ ] is a letter not guessed if it is " ". The '   ' is a delimiter for words"
    write-host "Letters Available: In [ ] is the available letters"
    write-host "Letters Consumed : In [ ] is the letters already guessed"
    write-host "Power Line Wheel : In [ ] is the point value"
    write-host "Power Increment  : In [ ] is the the power provided + random of 1-7 to increment against power line wheel"
    write-host "All Turn $($game.allturn) : The words are a helper for the next step."
    write-host ""

    write-host ""
    write-host "Hello, $invite have been invited to by $login."    
    $login = read-host "Do you want to play? If yes please enter your Login. If no please state no."
    if (($game.players | ? {$_.login -eq $login})) {
        write-host "Welcome Back $login"
        foreach ($i in $game.players) {
            if ($i.login -eq $login) {
                $i.playing = $true
            }
        }
        $rounds = [int](read-host "How many rounds do you want to play?")
    } else {
        write-host  "Welcome New Player $login"
        $player = [pscustomobject]@{
            login = $login
            turn = $false
            playing = $true
            requested_rounds = $rounds
            points = 0
            lastturnpower = 0
            lastturnspin = 0
            lastturnwheelvalue = 0
            lastturnguess = $null
            lastturnguesstrue = $false
            lastturnguessfound = 0
        }
        $game.players += $player
        $rounds = [int](read-host "How many rounds do you want to play?")
    }
    
    $invite = read-host "Do you want to invite anyone else? If yes please provide the AI Players' any property and I'll go search, if not state no"
    cls
}
#endregion
#region math find average of all players requested rounds.
$math = 0   
$game.players.requested_rounds | % {$math += $_}
$game.playing = ($game.players | ? {$_.playing -eq $true})
$game.rounds_requested_average = [math]::ceiling($math/($game.playing).count)
#select random game without anyone played
$game.round = random -SetSeed $([int](Get-Date -Format "ss")+1) -Maximum $game.wordlist.count
while (($playing.rounds_number_played | Sort-Object -Unique) -contains $game.round) {
    $game.round = random -SetSeed $([int](Get-Date -Format "ss")+1) -Maximum $game.wordlist.count
}
$game | Add-Member -NotePropertyName round_details -NotePropertyValue $game.wordlist[$game.round] -Force
#endregion
#region game start
$game 
while ($game.on -eq $true) {
    
    cls
    #region player turn
    if (!($game.playing.login.count -eq 1)) {
        $game.turn++
        if ($game.turn -eq ($game.playing.count)) {
            $game.turn = 0
            $game.allturn++
        }
        $game.playing | % {$_.turn = $false}
        $game.playing[$game.turn].turn = $true  
    } else {
        $game.playing[0].turn = $true
        $game.allturn++
    }
    #endregion
    #region dashboard
    Invoke-Command -ScriptBlock $dashboard
    #endregion
    #region spin
    $game.phase = "spin"
    if ([string]::IsNullOrEmpty($c)) {
        $c = 0     
    }
    $game.power = [int](read-host "All Turn $($game.allturn) : How much power to spin the wheel? There is a random +1 to +7 on each spin")
    $game.system_history += "All Turn $($game.allturn) : $($game.playing[$game.turn].login), How much power to spin the wheel? There is a random +1 to +7 on each spin"
    $game.spin =  (4+$game.power)+(random -Minimum -3 -Maximum 3)
    $game.playing[$game.turn].lastturnpower = $game.power
    $game.playing[$game.turn].lastturnspin = $game.spin   
    
    write-host "All Turn $($game.allturn):   $($game.playing[$game.turn].login), A power of $($game.power) was used to create a total spin of $($game.spin)"
    $game.system_history += "All Turn $($game.allturn) : $($game.playing[$game.turn].login), A power of $($game.power) was used to create a total spin of $($game.spin)"
    $c = [int]($game.board | ? {$_.arrow -eq $true}).dial
    $game.shold = $game.spin
    while ($game.spin -ne 0) {
        $c++
        $game.spin--
        if ($c -eq 25) {
            $c=0
        }
        $game.board | Add-Member -NotePropertyName arrow -NotePropertyValue $false -Force
        $game.board[$c].arrow = $true
        #region dashboard
        Invoke-Command -ScriptBlock $dashboard
        #endregion
        #write-host "Power: $($game.power) Spin Power: $($game.spin)"
        sleep .25           
    }
    $game | Add-Member -NotePropertyName "wheelvalue" -NotePropertyValue 0 -force
    $game.wheelvalue = ($game.board | ? {$_.arrow -eq $true}).value
    $game.playing[$game.turn].lastturnwheelvalue = $game.wheelvalue
    if ($game.wheelvalue -eq 0) {
        write-host "All Turn $($game.allturn) : $($game.playing[$game.turn].login), So sorry you got 0, you lose a turn."
        $game.system_history +=  "All Turn $($game.allturn) : $($game.playing[$game.turn].login), So sorry you got 0, you lose a turn."
        continue
    #endregion
    #region letter
    } else {
        $letter = read-host "All Turn $($game.allturn) : $($game.playing[$game.turn].login), you got $($game.wheelvalue), what letter do you want to guess?"
        $game.system_history +=  "All Turn $($game.allturn) : $($game.playing[$game.turn].login), you got $($game.wheelvalue), what letter do you want to guess?"
        $game.playing[$game.turn].lastturnguess = $letter
    }
    $game.phase = "letter"
    if ($letter -in $game.round_details.letters.letter) {
        foreach ($i in $game.board) {
            if ($letter -eq $i.letter) {
                $i.used = $true
            }       
        }
        foreach ($i in $game.round_details.letters) {
            if ($i.letter -eq $letter) {
                $i.guessed = $true
                $game.playing[$game.turn].points += $($game.wheelvalue)
                #region dashboard
                Invoke-Command -ScriptBlock $dashboard
                #endregion
                #sleep 1
            }
        }
        write-host "All Turn $($game.allturn) : $($game.playing[$game.turn].login), DING! The letter $letter was found $(@($game.round_details.letters | ? {$_.letter -eq $letter}).count) time(s), awarding you, $($game.playing[$game.turn].login) $((@($game.round_details.letters | ? {$_.letter -eq $letter}).count)*$($game.wheelvalue)) Points!"      
        $game.system_history +=  "All Turn $($game.allturn) : $($game.playing[$game.turn].login), DING! The letter $letter was found $(($game.round_details.letters | ? {$_.letter -eq $letter}).count) time(s), awarding you, $($game.playing[$game.turn].login) $((($game.round_details.letters | ? {$_.letter -eq $letter}).count)*$($game.wheelvalue)) Points!"
        $game.system_history_allturn += "All Turn $($game.allturn) : Player:[$($game.playing[$game.turn].login)] Power:[$($game.shold)] Wheel:[$($game.wheelvalue)] Guessed:[$letter] Outcome:[Correct] Count:[$(@($game.round_details.letters | ? {$_.letter -eq $letter}).count)] Points:[$((@($game.round_details.letters | ? {$_.letter -eq $letter}).count)*$($game.wheelvalue))]"
    } else {
        foreach ($i in $game.board) {
            if ($letter -eq $i.letter) {
                $i.used = $true
            }       
        }
        #region dashboard
        Invoke-Command -ScriptBlock $dashboard
        #endregion
        write-host "All Turn $($game.allturn) : $($game.playing[$game.turn].login), ZZZT! The letter $letter was not found. Sorry."
        $game.system_history += "All Turn $($game.allturn) : $($game.playing[$game.turn].login), ZZZT! The letter $letter was not found. Sorry."
        $game.system_history_allturn += "All Turn $($game.allturn) : Player:[$($game.playing[$game.turn].login)] Power:[$($game.shold)] Wheel:[$($game.wheelvalue)] Guessed:[$letter] Outcome:[Incorrect] Count:[$(@($game.round_details.letters | ? {$_.letter -eq $letter}).count)] Points:[$((@($game.round_details.letters | ? {$_.letter -eq $letter}).count)*$($game.wheelvalue))]"
    }
    #endregion
    #region phrase finished?
    if (!($game.round_details.letters | ? {$_.guessed -eq $false})) {
        write-host "GAME OVER"
        write-host "WINNER: $(($game.playing | Sort-Object points -Descending)[0])"
        sleep 1
        BREAK
    } else {
        sleep 1
        pause
    }
    #endregion
}
#endregion