|
| 1 | +# Configuration |
| 2 | + |
| 3 | +The configuration of basalt is written using [toml]. |
| 4 | +This configuration is used by the [`basalt-cli`] and the [`basalt-server`] |
| 5 | +to host a competition. |
| 6 | + |
| 7 | +[toml]: https://toml.io/en/v1.0.0 |
| 8 | +[`basalt-cli`]: https://github.com/basalt-rs/basalt-cli |
| 9 | +[`basalt-server`]: https://github.com/basalt-rs/basalt-server |
| 10 | + |
| 11 | +The configuration is broken up into four main sections: |
| 12 | + |
| 13 | +- [Runtime Config](./runtime.md) |
| 14 | +- [Setup Config](./setup.md) |
| 15 | +- [Language Config](./languages.md) |
| 16 | +- [Account Config](./account.md) |
| 17 | +- [Packet Config](./packet.md) |
| 18 | + |
| 19 | +## Example |
| 20 | + |
| 21 | +An example configuration is shown below. |
| 22 | + |
| 23 | +```toml |
| 24 | +# Host competition on port 1234 |
| 25 | +port = 1234 |
| 26 | + |
| 27 | +# Setup configuration |
| 28 | +[setup] |
| 29 | +# Install `opam` package |
| 30 | +install = ''' |
| 31 | +apt-get install opam |
| 32 | +''' |
| 33 | + |
| 34 | +# Initialise opam so we can run ocaml |
| 35 | +init = ''' |
| 36 | +opam init -y |
| 37 | +eval $(opam env) |
| 38 | +''' |
| 39 | + |
| 40 | +# Language configuration |
| 41 | +[languages] |
| 42 | +# Enable python3 default |
| 43 | +python3 = "*" |
| 44 | +# Enable built-in Java 21 |
| 45 | +java = "21" |
| 46 | +# Add custom `ocaml` language type |
| 47 | +[languges.ocaml] |
| 48 | +build = "ocamlc -o out {{SOURCEFILE}}" |
| 49 | +run = "./out" |
| 50 | + |
| 51 | + |
| 52 | +# Account configurations |
| 53 | +[[accounts.admins]] |
| 54 | +name = "Host" |
| 55 | +password = "HostP@ssword1" |
| 56 | + |
| 57 | +[[accounts.competitors]] |
| 58 | +name = "Team1" |
| 59 | +password = "Team1P@ssword" |
| 60 | + |
| 61 | +[[accounts.competitors]] |
| 62 | +name = "Team2" |
| 63 | +password = "Team2P@ssword" |
| 64 | + |
| 65 | + |
| 66 | +# packet configuration |
| 67 | +[packet] |
| 68 | +title = "Example Packet" |
| 69 | +preamble = ''' |
| 70 | +This packet includes problems of a difficulty *vastly* |
| 71 | +surpassing the capabilities of the average computer |
| 72 | +science student. Be wary as these problems will |
| 73 | +certainly give you great intellectual trouble. There |
| 74 | +is little hope for anyone without a Ph.D in computer |
| 75 | +science. |
| 76 | +
|
| 77 | +If you decide to attempt these problems anyways, good |
| 78 | +luck. You will be rewarded for swiftness in your answers. |
| 79 | +''' |
| 80 | + |
| 81 | +# Add a problem to this packet that requires the competitor to reverse a |
| 82 | +# string |
| 83 | +[[packet.problems]] |
| 84 | +title = "Reversing a string" |
| 85 | +description = ''' |
| 86 | +Reversing a string is one of the most _basic_ algorithmic |
| 87 | +problems for a beginner computer science student to solve. |
| 88 | +
|
| 89 | +Solve it. |
| 90 | +''' |
| 91 | + |
| 92 | +# Simple "hello" -> "olleh" test |
| 93 | +# Since this is the first test that is visible, it will be shown as the |
| 94 | +# example to the user. |
| 95 | +[[packet.problems.tests]] |
| 96 | +input = "hello" |
| 97 | +output = "olleh" |
| 98 | +visible = true |
| 99 | + |
| 100 | +[[packet.problems.tests]] |
| 101 | +input = "world" |
| 102 | +output = "dlrow" |
| 103 | +visible = true |
| 104 | + |
| 105 | +# Test that is not visible, and thus will not show the input or expected |
| 106 | +# output to the competitor. |
| 107 | +# This test is still used for scoring the competitor's solution. |
| 108 | +[[packet.problems.tests]] |
| 109 | +input = "" |
| 110 | +output = "" |
| 111 | + |
| 112 | +[[packet.problems.tests]] |
| 113 | +input = "aa" |
| 114 | +output = "aa" |
| 115 | + |
| 116 | +[[packet.problems.tests]] |
| 117 | +input = "racecar" |
| 118 | +output = "racecar" |
| 119 | +``` |
| 120 | + |
| 121 | +## Imports |
| 122 | + |
| 123 | +Because these configuration files can easily become out of hand, we |
| 124 | +offer the ability to import sections of the file using `import`. |
| 125 | + |
| 126 | +This example shows many sections broken into their own files. Of |
| 127 | +course, if only want to take certain sections out, you may. |
| 128 | + |
| 129 | +```toml |
| 130 | +# In config.toml |
| 131 | + |
| 132 | +port = 1234 # Host competition on port 1234 |
| 133 | + |
| 134 | +setup = { import = "./setup.toml" } |
| 135 | +languages = { import = "./languages.toml" } |
| 136 | +accounts = { import = "./accounts.toml" } |
| 137 | +packet = { import = "./packet.toml" } |
| 138 | +``` |
| 139 | + |
| 140 | +```toml |
| 141 | +# In setup.toml |
| 142 | + |
| 143 | +# Install `opam` package |
| 144 | +install = ''' |
| 145 | +apt-get install opam |
| 146 | +''' |
| 147 | + |
| 148 | +# Initialise opam so we can run ocaml |
| 149 | +init = ''' |
| 150 | +opam init -y |
| 151 | +eval $(opam env) |
| 152 | +''' |
| 153 | +``` |
| 154 | + |
| 155 | +```toml |
| 156 | +# In languages.toml |
| 157 | + |
| 158 | +python3 = "*" # Enable python3 default |
| 159 | +java = "21" # Enable built-in Java 21 |
| 160 | + |
| 161 | +[ocaml] # Add custom `ocaml` language type |
| 162 | +build = "ocamlc -o out {{SOURCEFILE}}" |
| 163 | +run = "./out" |
| 164 | +``` |
| 165 | + |
| 166 | +```toml |
| 167 | +# In accounts.toml |
| 168 | +[[admins]] |
| 169 | +name = "Host" |
| 170 | +password = "HostP@ssword1" |
| 171 | + |
| 172 | +[[competitors]] |
| 173 | +name = "Team1" |
| 174 | +password = "Team1P@ssword" |
| 175 | + |
| 176 | +[[competitors]] |
| 177 | +name = "Team2" |
| 178 | +password = "Team2P@ssword" |
| 179 | +``` |
| 180 | + |
| 181 | +```toml |
| 182 | +# In packet.toml |
| 183 | +title = "Example Packet" |
| 184 | +preamble = ''' |
| 185 | +This packet includes problems of a difficulty *vastly* |
| 186 | +surpassing the capabilities of the average computer |
| 187 | +science student. Be wary as these problems will |
| 188 | +certainly give you great intellectual trouble. There |
| 189 | +is little hope for anyone without a Ph.D in computer |
| 190 | +science. |
| 191 | +
|
| 192 | +If you decide to attempt these problems anyways, good |
| 193 | +luck. You will be rewarded for swiftness in your answers. |
| 194 | +''' |
| 195 | + |
| 196 | +problems = [{ import = "./problem1.toml" }] |
| 197 | +``` |
| 198 | + |
| 199 | +```toml |
| 200 | +# In problem1.toml |
| 201 | +title = "Reversing a string" |
| 202 | +description = ''' |
| 203 | +Reversing a string is one of the most _basic_ algorithmic |
| 204 | +problems for a beginner computer science student to solve. |
| 205 | +
|
| 206 | +Solve it. |
| 207 | +''' |
| 208 | + |
| 209 | +# Simple "hello" -> "olleh" test |
| 210 | +# Since this is the first test that is visible, it will be shown as the |
| 211 | +# example to the user. |
| 212 | +[[tests]] |
| 213 | +input = "hello" |
| 214 | +output = "olleh" |
| 215 | +visible = true |
| 216 | + |
| 217 | +[[tests]] |
| 218 | +input = "world" |
| 219 | +output = "dlrow" |
| 220 | +visible = true |
| 221 | + |
| 222 | +# Test that is not visible, and thus will not show the input or expected |
| 223 | +# output to the competitor. |
| 224 | +# This test is still used for scoring the competitor's solution. |
| 225 | +[[tests]] |
| 226 | +input = "" |
| 227 | +output = "" |
| 228 | + |
| 229 | +[[tests]] |
| 230 | +input = "aa" |
| 231 | +output = "aa" |
| 232 | + |
| 233 | +[[tests]] |
| 234 | +input = "racecar" |
| 235 | +output = "racecar" |
| 236 | +``` |
0 commit comments