Skip to content

Commit 0e74dc5

Browse files
committed
refactor: remove unused makeMove function from utils
1 parent 4adcaa2 commit 0e74dc5

File tree

1 file changed

+0
-64
lines changed

1 file changed

+0
-64
lines changed

internal/utils.go

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,13 @@
11
package internal
22

33
import (
4-
"bytes"
5-
"encoding/json"
6-
"fmt"
7-
"io"
8-
"net/http"
94
"os"
105
"path/filepath"
11-
"time"
126

137
"github.com/codecrafters-io/tester-utils/test_case_harness"
148
"github.com/corentings/chess"
159
)
1610

17-
func makeMove(fenStr string) (string, error) {
18-
fen, err := chess.FEN(fenStr)
19-
if err != nil {
20-
return "", err
21-
}
22-
23-
game := chess.NewGame(fen)
24-
25-
// Determine turn color
26-
turn := "white"
27-
if game.Position().Turn() == chess.Black {
28-
turn = "black"
29-
}
30-
31-
// Prepare request body
32-
type requestBody struct {
33-
Fen string `json:"fen"`
34-
Turn string `json:"turn"`
35-
FailedMoves []string `json:"failed_moves"`
36-
}
37-
38-
body := requestBody{
39-
Fen: fenStr,
40-
Turn: turn,
41-
FailedMoves: []string{},
42-
}
43-
44-
jsonBody, err := json.Marshal(body)
45-
if err != nil {
46-
return "", fmt.Errorf("error marshaling request body: %v", err)
47-
}
48-
49-
client := &http.Client{
50-
Timeout: 5 * time.Second,
51-
}
52-
53-
resp, err := client.Post(
54-
"http://localhost:8000/move",
55-
"application/json",
56-
bytes.NewBuffer(jsonBody),
57-
)
58-
if err != nil {
59-
return "", fmt.Errorf("error making request: %v", err)
60-
}
61-
defer resp.Body.Close()
62-
63-
responseBody, err := io.ReadAll(resp.Body)
64-
if err != nil {
65-
return "", fmt.Errorf("error reading response: %v", err)
66-
}
67-
68-
if resp.StatusCode != http.StatusOK {
69-
return "", fmt.Errorf("failed to make move, got status %d: %s", resp.StatusCode, string(responseBody))
70-
}
71-
72-
return string(responseBody), nil
73-
}
74-
7511
func checkFEN(FEN string) bool {
7612
_, err := chess.FEN(FEN)
7713
if err != nil {

0 commit comments

Comments
 (0)