@@ -123,13 +123,34 @@ export const processPendingAction = (state: GameState) => {
123
123
124
124
const getEvenlySpacedHueColors = ( n : number ) =>
125
125
Array . from ( { length : n } , ( _ , i ) => {
126
- const angle = ( i / n ) * 2 * Math . PI
127
- return `hsl(${ angle * ( 180 / Math . PI ) } , 50 %, 50%)`
126
+ const angle = ( ( i + 0.5 ) / n ) * 2 * Math . PI
127
+ return `hsl(${ Math . round ( angle * ( 180 / Math . PI ) ) } , 35 %, 50%)`
128
128
} )
129
129
130
+ const distributeColorsWithFixedStep = ( colors : string [ ] ) : string [ ] => {
131
+ const n = colors . length
132
+ const step = 3
133
+
134
+ if ( n > 1 && n % step === 0 ) {
135
+ throw new Error (
136
+ `Step size of ${ step } is not coprime to array length ${ n } . The output array may not contain all original elements if a random start is used.`
137
+ )
138
+ }
139
+
140
+ const startIndex = Math . floor ( Math . random ( ) * n )
141
+ const result : string [ ] = [ ]
142
+ let currentIndex = startIndex
143
+ for ( let i = 0 ; i < n ; i ++ ) {
144
+ result . push ( colors [ currentIndex ] )
145
+ currentIndex = ( currentIndex + step ) % n
146
+ }
147
+
148
+ return result
149
+ }
150
+
130
151
const getNewGameState = ( roomId : string , settings : GameSettings ) : GameState => ( {
131
152
roomId,
132
- availablePlayerColors : shuffle ( getEvenlySpacedHueColors ( MAX_PLAYER_COUNT ) ) ,
153
+ availablePlayerColors : distributeColorsWithFixedStep ( getEvenlySpacedHueColors ( MAX_PLAYER_COUNT ) ) ,
133
154
players : [ ] ,
134
155
deck : shuffle ( createDeckForPlayerCount ( 0 ) ) ,
135
156
pendingInfluenceLoss : { } ,
0 commit comments