Unsurprisingly, the general question has also been addressed in the mathematical research literature.
Firstly, in the article V. Chvátal, "Mastermind", Combinatorica 3(3) (1983), pp. 325-329 (yes, the title of the paper is simply "Mastermind").
Mastermind is a game for two players, called S.F. and the P.G.O.M. In the
beginning, S.F. creates a "mystery vector" $m = [ m_1 , m_2 , . . . , m_n]$ such that each $m_i$ is one of the "colors" $1, 2, ..., k$. The P.G.O.M. (who knows both $n$ and $k$) then proceeds to determine $m$ by asking a number of questions, which are answered by S.F. Each question $q$ is a vector $[q_1, q_2 ,..., q_n]$ such that each $q_i$ is one of the k colors; each answer consists of a pair of numbers $a(q, m), b(q, m)$ such that $a(q, m)$ is the number of subscripts $i$ with $q_i = m_i$ and $b(q, m)$ is the largest $a(q, \tilde{m})$ with $\tilde{m}$ running through all the permutations of $m$.
That just describes Mastermind in more mathematical language, with $k$ colours and a code of length $n$ (amusingly, the reverse of your original notation - that's two white pegs for you!) - the same notation as in the updated version of the OP.
In the commercial version that became popular a few years ago, $n = 4$ and
$k = 6$ (with each answer represented by $a(q, m)$ black pins and $b(q, m ) - a ( q , m)$ white pins); Knuth [1] has shown that four questions suffice to determine $m$ in this case. The generalization to arbitrary $n$ and $k$ was suggested by Pierre Duchet, who asked for
(i) the smallest number $f ( n , k)$ such that the P.G.O.M. can determine any $m$ by asking $f(n, k)$ questions (waiting, as usual, for each answer before asking the next question), and
(ii) the smallest number $g(n, k)$ such that the P.G.O.M. can determine any $m$ by asking $g(n, k)$ questions at once (without waiting for the answers).
The number you want is $f(n,k)$, and this paper proves (Theorem 2) that:
If $n \leq k \leq n^2$ then $f(n, k) \leq 2n\log k + 4n$ [where "log" denotes the logarithm to base $2$].
Then, in the article W. Goddard, "Mastermind revisited", J. Combin. Math. Combin. Comput. 51 (2004), pp. 215-220, an exact formula is given for the case $n=2$ (only 2 positions, arbitrarily many colours): $$f(2,k)=\lfloor k/2\rfloor+2.$$
The article B. Doerr, C. Doerr, R. Spöhel, H. Thomas, "Playing mastermind with many colors", Journal of the ACM 63(5) (2016), pp. 1-23 improved Chvátal's bounds, and J. J. Merelo, "The game of MasterMind in 2020: an overview of literature" (link goes to PDF download) says that:
Mastermind is in 2020 still an open problem. Advances have been made in the theoretical arena, finding tight lower bounds to the number of queries that need to be made to find a solution, and in the heuristic arena, with finding how scoring functions for plausible solutions, or combinations of them, are able to find the solution faster by extracting an optimal amount of information from the oracle. [...] MasterMind is still a NP-complete problem, and spaces of solutions that have been researched are still very small; scaling of solutions is what we would expect it to be. [...] The search for a final solution is still open. It might be that there’s no single heuristic or combination of them that is able to find, in every move, the optimal combination for every possible code; this needs to be proved theoretically, however, Meanwhile, we will probably see in the next few years tighter bounds to the number of solutions, and faster solutions to problems that have double-digit number of “colors” and length.
This seems to be more or less the state of the art: upper bounds are known for the answer to your question, but no exact solution, neither for general $n$ nor for general $k$, except in some particularly simple cases like when there are only 2 pegs in the code.
How I found this answer:
- Start from the Wikipedia page linked in the OP, and go to the Knuth citation that was mentioned.
- Search for that paper on Google Scholar, where it has 244 citations.
- Check the list of articles that cite Knuth's (that's where further results beyond his would be found); that search yielded the Chvatal article.
- Search within citing articles (those citing Chvatal, this time) for the keyword "mastermind"; that search found the Goddard and Doerr et al. articles.
- Search within citing articles (those citing the 2016 article) for the keyword "mastermind" again; that search found the Merelo article, which is only a few years in the past.
Disclaimer: I saw this question in chat before the OP posted it, but I didn't start my research for answering it until it was already posted on the site, so as not to have any advantage over other potential answerers who might not be in chat.