The classic game of noughts and crosses... in Powershell!
- Download the zip file or pull from this repository
- Open Powershell IDE (Comes with Windows OS) with administrative rights (Right click, Run as administrator)
- Open the noughts-and-crosses.ps1 file
- Run the command: Set-ExecutionPolicy Unrestricted
- Type "Y" for the prompt (Please don't be scared by the stern warning thrown. Because this script doesn't have a certificate, you need to change the execution policy otherwise Powershell will be mean and won't run the script. I assure you there isn't an ounce of maliciousness in this script.)
- Run the noughts-and-crosses.ps1 file: Press F5
- When prompted, choose whether 1 or 2 players will be participating in this splendid game of noughts and crosses (Or perhaps choose 0 if your feeling adventurous).
- When prompted, choose where to put your 'token' on the board by entering in x,y coordinates, with reference from below:
1 | |
-----------
y 2 | |
-----------
3 | |
1 2 3
x
- ???
- Have fun!
Yes this Powershell script actually has unit tests courtesy of Pester! But why? While I don't have any plans on continuing development, the tests will help anyone who wants to work with this code in the future. On that note, the tests only run correctly when you run the test file individually, as opposed to calling Invoke-Pester in a Powershell shell in the directory. I believe this is due to a bug on global variable scoping in Pester itself.
If someone wipes the cobwebs off this repository some time in the future, a few notes on the code if you want to tinker with it:
- The noughts-and-crosses.ps1 file is the runnable game file which is essentially a loop of game logic.
- The noughts-and-crosses-functions.ps1 file has the core functions.
- The noughts-and-crosses-functions-tests.ps1 file contains, you guessed it, tests for the core functions.
- The game doesn't seem to run on anything other than the Powershell IDE console. I believe this is due to either modules not being loaded or how different consoles represent text.