Beste medetweakers,
Ik zal even de situatie schetsen waarin ik mij bevind;
Ik heb zelf niet hele goede ervaring met programmeren of scripting, ik volg nu het vak "scripting concepts", dit vak leert mij de basics van Powershell te gebruiken.
Bij elke les krijgen wij huiswerk opdrachten die altijd wel goed te maken waren, ik zat vaak wel eens vast maar ik wist wel waar het probleem zat (en het lukte mij ook altijd het probleem op te lossen).
Nu kregen wij ineens op een 4 op een rij spel te maken; hulp van de leraar krijg ik pas vrijdag en dan moet ook het script ingeleverd worden (de leraar is een door school ingehuurd persoon die enkel zijn e-mail op de vrijdag bekijkt).
De opdracht was vrijdag beschikbaar en ik ben er eigenlijk direct ermee aan de slag gegaan die dag.
Ik heb wel al wat aan het script gedaan maar dit was eigenlijk vrij snel klaar, ik loop gewoon compleet vast op het het volgende:
wanneer is iets 4 op een rij?
er mogen geen zwevende blokjes zijn
op regel 126 & 127 lukt het niet om enkel input als [A-J][1-10] toe te laten (validate-move functie)
De rest, het switchen tussen spelers, de input werkend maken en een gelijk spel toelaten lukt zonder enig probleem.
Als dit gewenst is wil ik ook mijn model die ik voorafgaand aan deze code gemaakt heb meesturen.
Als ik enkel even een tip krijg hoe ik dit kan oplossen moet het denk ik wel lukken.
Alle hulp is welkom, alvast ontzettend veel bedankt!
Gr,
Bart
Mijn code:
Clear-Host
$move = ""
$moves = 0
$player = "X"
[boolean]$running = 1
$gelijkspel = "False"
$A1 = "_"
$A2 = "_"
$A3 = "_"
$A4 = "_"
$A5 = "_"
$A6 = "_"
$A7 = "_"
$A8 = "_"
$A9 = "_"
$A10 = "_"
$B1 = "_"
$B2 = "_"
$B3 = "_"
$B4 = "_"
$B5 = "_"
$B6 = "_"
$B7 = "_"
$B8 = "_"
$B9 = "_"
$B10 = "_"
$C1 = "_"
$C2 = "_"
$C3 = "_"
$C4 = "_"
$C5 = "_"
$C6 = "_"
$C7 = "_"
$C8 = "_"
$C9 = "_"
$C10 = "_"
$D1 = "_"
$D2 = "_"
$D3 = "_"
$D4 = "_"
$D5 = "_"
$D6 = "_"
$D7 = "_"
$D8 = "_"
$D9 = "_"
$D10 = "_"
$E1 = "_"
$E2 = "_"
$E3 = "_"
$E4 = "_"
$E5 = "_"
$E6 = "_"
$E7 = "_"
$E8 = "_"
$E9 = "_"
$E10 = "_"
$F1 = "_"
$F2 = "_"
$F3 = "_"
$F4 = "_"
$F5 = "_"
$F6 = "_"
$F7 = "_"
$F8 = "_"
$F9 = "_"
$F10 = "_"
$G1 = "_"
$G2 = "_"
$G3 = "_"
$G4 = "_"
$G5 = "_"
$G6 = "_"
$G7 = "_"
$G8 = "_"
$G9 = "_"
$G10 = "_"
$H1 = "_"
$H2 = "_"
$H3 = "_"
$H4 = "_"
$H5 = "_"
$H6 = "_"
$H7 = "_"
$H8 = "_"
$H9 = "_"
$H10 = "_"
$I1 = "_"
$I2 = "_"
$I3 = "_"
$I4 = "_"
$I5 = "_"
$I6 = "_"
$I7 = "_"
$I8 = "_"
$I9 = "_"
$I10 = "_"
$J1 = "_"
$J2 = "_"
$J3 = "_"
$J4 = "_"
$J5 = "_"
$J6 = "_"
$J7 = "_"
$J8 = "_"
$J9 = "_"
$J10 = "_"
#Functies
Function Spelbord{
Write-Host " A B C D E F G H I J"
Write-Host " 10 $A10 | $B10 | $C10 | $D10 | $E10 | $F10 | $G10 | $H10 | $I10 | $J10 |"
Write-Host " 9 $A9 | $B9 | $C9 | $D9 | $E9 | $F9 | $G9 | $H9 | $I9 | $J9 |"
Write-Host " 8 $A8 | $B8 | $C8 | $D8 | $E8 | $F8 | $G8 | $H8 | $I8 | $J8 |"
Write-Host " 7 $A7 | $B7 | $C7 | $D7 | $E7 | $F7 | $G7 | $H7 | $I7 | $J7 |"
Write-Host " 6 $A6 | $B6 | $C6 | $D6 | $E6 | $F6 | $G6 | $H6 | $I6 | $J6 |"
Write-Host " 5 $A5 | $B5 | $C5 | $D5 | $E5 | $F5 | $G5 | $H5 | $I5 | $J5 |"
Write-Host " 4 $A4 | $B4 | $C4 | $D4 | $E4 | $F4 | $G4 | $H4 | $I4 | $J4 |"
Write-Host " 3 $A3 | $B3 | $C3 | $D3 | $E3 | $F3 | $G3 | $H3 | $I3 | $J3 |"
Write-Host " 2 $A2 | $B2 | $C2 | $D2 | $E2 | $F2 | $G2 | $H2 | $I2 | $J2 |"
Write-Host " 1 $script:A1 | $B1 | $C1 | $D1 | $E1 | $F1 | $G1 | $H1 | $I1 | $J1 |"
$move = Read-Host "Geef de coordinaten aan"
$move
}
function Validate-Move{
if ($move.length -eq 2) {
if ($move -match "[A-J][1-10]") {
$result = "Valid"
}
else {
$result = "Invalid"
}
}
else {
$result = "Invalid"
}
if (($move -eq "A1") -and ($A1 -ne "_")) {$result = "Invalid"}
if (($move -eq "A2") -and ($A2 -ne "_")) {$result = "Invalid"}
if (($move -eq "A3") -and ($A3 -ne "_")) {$result = "Invalid"}
if (($move -eq "A4") -and ($A4 -ne "_")) {$result = "Invalid"}
if (($move -eq "A5") -and ($A5 -ne "_")) {$result = "Invalid"}
if (($move -eq "A6") -and ($A6 -ne "_")) {$result = "Invalid"}
if (($move -eq "A7") -and ($A7 -ne "_")) {$result = "Invalid"}
if (($move -eq "A8") -and ($A8 -ne "_")) {$result = "Invalid"}
if (($move -eq "A9") -and ($A9 -ne "_")) {$result = "Invalid"}
if (($move -eq "A10") -and ($A10 -ne "_")) {$result = "Invalid"}
if (($move -eq "B1") -and ($B1 -ne "_")) {$result = "Invalid"}
if (($move -eq "B2") -and ($B2 -ne "_")) {$result = "Invalid"}
if (($move -eq "B3") -and ($B3 -ne "_")) {$result = "Invalid"}
if (($move -eq "B4") -and ($B4 -ne "_")) {$result = "Invalid"}
if (($move -eq "B5") -and ($B5 -ne "_")) {$result = "Invalid"}
if (($move -eq "B6") -and ($B6 -ne "_")) {$result = "Invalid"}
if (($move -eq "B7") -and ($B7 -ne "_")) {$result = "Invalid"}
if (($move -eq "B8") -and ($B8 -ne "_")) {$result = "Invalid"}
if (($move -eq "B9") -and ($B9 -ne "_")) {$result = "Invalid"}
if (($move -eq "B10") -and ($B10 -ne "_")) {$result = "Invalid"}
if (($move -eq "C1") -and ($C1 -ne "_")) {$result = "Invalid"}
if (($move -eq "C2") -and ($C2 -ne "_")) {$result = "Invalid"}
if (($move -eq "C3") -and ($C3 -ne "_")) {$result = "Invalid"}
if (($move -eq "C4") -and ($C4 -ne "_")) {$result = "Invalid"}
if (($move -eq "C5") -and ($C5 -ne "_")) {$result = "Invalid"}
if (($move -eq "C6") -and ($C6 -ne "_")) {$result = "Invalid"}
if (($move -eq "C7") -and ($C7 -ne "_")) {$result = "Invalid"}
if (($move -eq "C8") -and ($C8 -ne "_")) {$result = "Invalid"}
if (($move -eq "C9") -and ($C9 -ne "_")) {$result = "Invalid"}
if (($move -eq "C10") -and ($C10 -ne "_")) {$result = "Invalid"}
if (($move -eq "D1") -and ($D1 -ne "_")) {$result = "Invalid"}
if (($move -eq "D2") -and ($D2 -ne "_")) {$result = "Invalid"}
if (($move -eq "D3") -and ($D3 -ne "_")) {$result = "Invalid"}
if (($move -eq "D4") -and ($D4 -ne "_")) {$result = "Invalid"}
if (($move -eq "D5") -and ($D5 -ne "_")) {$result = "Invalid"}
if (($move -eq "D6") -and ($D6 -ne "_")) {$result = "Invalid"}
if (($move -eq "D7") -and ($D7 -ne "_")) {$result = "Invalid"}
if (($move -eq "D8") -and ($D8 -ne "_")) {$result = "Invalid"}
if (($move -eq "D9") -and ($D9 -ne "_")) {$result = "Invalid"}
if (($move -eq "D10") -and ($D10 -ne "_")) {$result = "Invalid"}
if (($move -eq "E1") -and ($E1 -ne "_")) {$result = "Invalid"}
if (($move -eq "E2") -and ($E2 -ne "_")) {$result = "Invalid"}
if (($move -eq "E3") -and ($E3 -ne "_")) {$result = "Invalid"}
if (($move -eq "E4") -and ($E4 -ne "_")) {$result = "Invalid"}
if (($move -eq "E5") -and ($E5 -ne "_")) {$result = "Invalid"}
if (($move -eq "E6") -and ($E6 -ne "_")) {$result = "Invalid"}
if (($move -eq "E7") -and ($E7 -ne "_")) {$result = "Invalid"}
if (($move -eq "E8") -and ($E8 -ne "_")) {$result = "Invalid"}
if (($move -eq "E9") -and ($E9 -ne "_")) {$result = "Invalid"}
if (($move -eq "E10") -and ($E10 -ne "_")) {$result = "Invalid"}
if (($move -eq "F1") -and ($F1 -ne "_")) {$result = "Invalid"}
if (($move -eq "F2") -and ($F2 -ne "_")) {$result = "Invalid"}
if (($move -eq "F3") -and ($F3 -ne "_")) {$result = "Invalid"}
if (($move -eq "F4") -and ($F4 -ne "_")) {$result = "Invalid"}
if (($move -eq "F5") -and ($F5 -ne "_")) {$result = "Invalid"}
if (($move -eq "F6") -and ($F6 -ne "_")) {$result = "Invalid"}
if (($move -eq "F7") -and ($F7 -ne "_")) {$result = "Invalid"}
if (($move -eq "F8") -and ($F8 -ne "_")) {$result = "Invalid"}
if (($move -eq "F9") -and ($F9 -ne "_")) {$result = "Invalid"}
if (($move -eq "F10") -and ($F10 -ne "_")) {$result = "Invalid"}
if (($move -eq "G1") -and ($G1 -ne "_")) {$result = "Invalid"}
if (($move -eq "G2") -and ($G2 -ne "_")) {$result = "Invalid"}
if (($move -eq "G3") -and ($G3 -ne "_")) {$result = "Invalid"}
if (($move -eq "G4") -and ($G4 -ne "_")) {$result = "Invalid"}
if (($move -eq "G5") -and ($G5 -ne "_")) {$result = "Invalid"}
if (($move -eq "G6") -and ($G6 -ne "_")) {$result = "Invalid"}
if (($move -eq "G7") -and ($G7 -ne "_")) {$result = "Invalid"}
if (($move -eq "G8") -and ($G8 -ne "_")) {$result = "Invalid"}
if (($move -eq "G9") -and ($G9 -ne "_")) {$result = "Invalid"}
if (($move -eq "G10") -and ($G10 -ne "_")) {$result = "Invalid"}
if (($move -eq "H1") -and ($H1 -ne "_")) {$result = "Invalid"}
if (($move -eq "H2") -and ($H2 -ne "_")) {$result = "Invalid"}
if (($move -eq "H3") -and ($H3 -ne "_")) {$result = "Invalid"}
if (($move -eq "H4") -and ($H4 -ne "_")) {$result = "Invalid"}
if (($move -eq "H5") -and ($H5 -ne "_")) {$result = "Invalid"}
if (($move -eq "H6") -and ($H6 -ne "_")) {$result = "Invalid"}
if (($move -eq "H7") -and ($H7 -ne "_")) {$result = "Invalid"}
if (($move -eq "H8") -and ($H8 -ne "_")) {$result = "Invalid"}
if (($move -eq "H9") -and ($H9 -ne "_")) {$result = "Invalid"}
if (($move -eq "H10") -and ($H10 -ne "_")) {$result = "Invalid"}
if (($move -eq "I1") -and ($I1 -ne "_")) {$result = "Invalid"}
if (($move -eq "I2") -and ($I2 -ne "_")) {$result = "Invalid"}
if (($move -eq "I3") -and ($I3 -ne "_")) {$result = "Invalid"}
if (($move -eq "I4") -and ($I4 -ne "_")) {$result = "Invalid"}
if (($move -eq "I5") -and ($I5 -ne "_")) {$result = "Invalid"}
if (($move -eq "I6") -and ($I6 -ne "_")) {$result = "Invalid"}
if (($move -eq "I7") -and ($I7 -ne "_")) {$result = "Invalid"}
if (($move -eq "I8") -and ($I8 -ne "_")) {$result = "Invalid"}
if (($move -eq "I9") -and ($I9 -ne "_")) {$result = "Invalid"}
if (($move -eq "I10") -and ($I10 -ne "_")) {$result = "Invalid"}
if (($move -eq "J1") -and ($J1 -ne "_")) {$result = "Invalid"}
if (($move -eq "J2") -and ($J2 -ne "_")) {$result = "Invalid"}
if (($move -eq "J3") -and ($J3 -ne "_")) {$result = "Invalid"}
if (($move -eq "J4") -and ($J4 -ne "_")) {$result = "Invalid"}
if (($move -eq "J5") -and ($J5 -ne "_")) {$result = "Invalid"}
if (($move -eq "J6") -and ($J6 -ne "_")) {$result = "Invalid"}
if (($move -eq "J7") -and ($J7 -ne "_")) {$result = "Invalid"}
if (($move -eq "J8") -and ($J8 -ne "_")) {$result = "Invalid"}
if (($move -eq "J9") -and ($J9 -ne "_")) {$result = "Invalid"}
if (($move -eq "J10") -and ($J10 -ne "_")) {$result = "Invalid"}
$result
}
function valid-input{
if($move -eq "A1"){$script:A1 = $player}
if($move -eq "A2"){$script:A2 = $player}
if($move -eq "A3"){$script:A3 = $player}
if($move -eq "A4"){$script:A4 = $player}
if($move -eq "A5"){$script:A5 = $player}
if($move -eq "A6"){$script:A6 = $player}
if($move -eq "A7"){$script:A7 = $player}
if($move -eq "A8"){$script:A8 = $player}
if($move -eq "A9"){$script:A9 = $player}
if($move -eq "A10"){$script:A10 = $player}
if($move -eq "B1"){$script:B1 = $player}
if($move -eq "B2"){$script:B2 = $player}
if($move -eq "B3"){$script:B3 = $player}
if($move -eq "B4"){$script:B4 = $player}
if($move -eq "B5"){$script:B5 = $player}
if($move -eq "B6"){$script:B6 = $player}
if($move -eq "B7"){$script:B7 = $player}
if($move -eq "B8"){$script:B8 = $player}
if($move -eq "B9"){$script:B9 = $player}
if($move -eq "B10"){$script:B10 = $player}
if($move -eq "C1"){$script:C1 = $player}
if($move -eq "C2"){$script:C2 = $player}
if($move -eq "C3"){$script:C3 = $player}
if($move -eq "C4"){$script:C4 = $player}
if($move -eq "C5"){$script:C5 = $player}
if($move -eq "C6"){$script:C6 = $player}
if($move -eq "C7"){$script:C7 = $player}
if($move -eq "C8"){$script:C8 = $player}
if($move -eq "C9"){$script:C9 = $player}
if($move -eq "C10"){$script:C10 = $player}
if($move -eq "D1"){$script:D1 = $player}
if($move -eq "D2"){$script:D2 = $player}
if($move -eq "D3"){$script:D3 = $player}
if($move -eq "D4"){$script:D4 = $player}
if($move -eq "D5"){$script:D5 = $player}
if($move -eq "D6"){$script:D6 = $player}
if($move -eq "D7"){$script:D7 = $player}
if($move -eq "D8"){$script:D8 = $player}
if($move -eq "D9"){$script:D9 = $player}
if($move -eq "D10"){$script:D10 = $player}
if($move -eq "E1"){$script:E1 = $player}
if($move -eq "E2"){$script:E2 = $player}
if($move -eq "E3"){$script:E3 = $player}
if($move -eq "E4"){$script:E4 = $player}
if($move -eq "E5"){$script:E5 = $player}
if($move -eq "E6"){$script:E6 = $player}
if($move -eq "E7"){$script:E7 = $player}
if($move -eq "E8"){$script:E8 = $player}
if($move -eq "E9"){$script:E9 = $player}
if($move -eq "E10"){$script:E10 = $player}
if($move -eq "F1"){$script:F1 = $player}
if($move -eq "F2"){$script:F2 = $player}
if($move -eq "F3"){$script:F3 = $player}
if($move -eq "F4"){$script:F4 = $player}
if($move -eq "F5"){$script:F5 = $player}
if($move -eq "F6"){$script:F6 = $player}
if($move -eq "F7"){$script:F7 = $player}
if($move -eq "F8"){$script:F8 = $player}
if($move -eq "F9"){$script:F9 = $player}
if($move -eq "F10"){$script:F10 = $player}
if($move -eq "G1"){$script:G1 = $player}
if($move -eq "G2"){$script:G2 = $player}
if($move -eq "G3"){$script:G3 = $player}
if($move -eq "G4"){$script:G4 = $player}
if($move -eq "G5"){$script:G5 = $player}
if($move -eq "G6"){$script:G6 = $player}
if($move -eq "G7"){$script:G7 = $player}
if($move -eq "G8"){$script:G8 = $player}
if($move -eq "G9"){$script:G9 = $player}
if($move -eq "G10"){$script:G10 = $player}
if($move -eq "H1"){$script:H1 = $player}
if($move -eq "H2"){$script:H2 = $player}
if($move -eq "H3"){$script:H3 = $player}
if($move -eq "H4"){$script:H4 = $player}
if($move -eq "H5"){$script:H5 = $player}
if($move -eq "H6"){$script:H6 = $player}
if($move -eq "H7"){$script:H7 = $player}
if($move -eq "H8"){$script:H8 = $player}
if($move -eq "H9"){$script:H9 = $player}
if($move -eq "H10"){$script:H10 = $player}
if($move -eq "I1"){$script:I1 = $player}
if($move -eq "I2"){$script:I2 = $player}
if($move -eq "I3"){$script:I3 = $player}
if($move -eq "I4"){$script:I4 = $player}
if($move -eq "I5"){$script:I5 = $player}
if($move -eq "I6"){$script:I6 = $player}
if($move -eq "I7"){$script:I7 = $player}
if($move -eq "I8"){$script:I8 = $player}
if($move -eq "I9"){$script:I9 = $player}
if($move -eq "I10"){$script:I10 = $player}
if($move -eq "J1"){$script:J1 = $player}
if($move -eq "J2"){$script:J2 = $player}
if($move -eq "J3"){$script:J3 = $player}
if($move -eq "J4"){$script:J4 = $player}
if($move -eq "J5"){$script:J5 = $player}
if($move -eq "J6"){$script:J6 = $player}
if($move -eq "J7"){$script:J7 = $player}
if($move -eq "J8"){$script:J8 = $player}
if($move -eq "J9"){$script:J9 = $player}
if($move -eq "J10"){$script:J10 = $player}
}
# De uiteindelijke code
Clear-Host
While($running -eq 1){
#hier vinden de zetten plaats
$move = spelbord
$validmove = Validate-Move
if($validmove -eq "Valid"){
$moves++
valid-input
}
else {
Clear-Host
Read-Host "`n`n`n`n`n`n`n`n`n`nInvalid Move. Press Enter to try again"
continue
}
# gelijk spel
if ($moves -eq 100) {
Write-Host `a
$gelijkspel = "True"
Write-Host "Het spel is geindigd in gelijkspel!"
$running = 0
continue
}
# het switchen in spelers
if ($running -eq 1) {
if ($player -eq "X") {
$player = "Y"
}
else {
$player = "X"
}
}
}